Java uses regular expressions to extract qualified strings

Source: Internet
Author: User
Import java. util. arraylist;
Import java. util. List;
Import java. util. RegEx. matcher;
Import java. util. RegEx. pattern;

/**
*

* Class Name: [string processing class]
*

*

* Class description: [string processing class]
*

*

* Module: Server _ [Tool]
*

*

* Creation Time: 6/1/09 pm
*

*
* @ Author lvhuiqing lv.hq@neusoft.com
* @ Version 1.0
*/
Public class stringutil {
/**
*

* Method Description: [use a regular expression to extract the mode of interest from the target string]
*

*
* @ Param target
* Target string
* @ Param Pattern
* Regular Expression used
*
* @ Return an array composed of strings that meet the pattern
*/
Public static list Abspattern (string target, string RegEx ){
List Result = NULL;
Try {
Pattern pattern = pattern. Compile (RegEx );
Matcher = pattern. matcher (target );
While (matcher. Find ()){
If (result = NULL)
Result = new arraylist ();
Result. Add (matcher. Group ());
}
} Catch (throwable e ){
E. printstacktrace ();
Return NULL;
}
Return result;
}

Public static void main (string [] ARGs ){
List List = stringutil
. Abspattern (
"Com. Neusoft. avnc. lbs. autonavi. server. Business. ymlocation. servlet. ymlocservlet ",
"(Business //.). +? (//. Servlet ))");
For (INT I = 0; I

  • Previous:Spring memo
  • Next article:Sequence related operation commands
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.