Configuring regular expressions in an XML file

Source: Internet
Author: User

Example xml:

<data type= "REGEX" >
<code>prop1</code>
<name> title </name>
<method>
<! [cdata[
(? i) (? <=bookname\: \ ") ([\u4e00-\u9fa5]+)
]]>
</method>
</data>

1) The regular contains < will be wrong, need to be processed;

2) Note the wording in the Java file is slightly different AH (backslash/) write one more result may not come out (⊙o⊙) OH


Example Java:

public class Testregex {
public static void Main (string[] args) throws Exception {

String str = "BookName: \" I want to seal the day \ ", CategoryName: \" fairy-man \ ", Subcategoryname: \" Classical fairy-man \ ";
String regex = "(? i) (? <=categoryname\\: \") ([\u4e00-\u9fa5]+)];
System.out.println (Getregexvalue (Regex, str, true). ToString ());

}

public static Object Getregexvalue (string regex, String html, Boolean islist) {

if (islist = = False) {
Pattern p = pattern.compile (regex);
Matcher Matcher = p.matcher (HTML);
return Matcher.find () = = true? Matcher.group (): null;
} else {
list<string> result = new arraylist<string> ();
Pattern p = pattern.compile (regex);
Matcher Matcher = p.matcher (HTML);
while (Matcher.find ()) {
Result.add (Matcher.group ());
}
return result;
}
}
}

Configuring regular expressions in an XML file

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.