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