例XML:
prop1
书名
(?i)(?<=BookName\: \")([\u4e00-\u9fa5]+)
]]>
1)正则中含有
2)注意和Java文件中的写法稍微不一样啊(反斜杠/) 多写一个结果就可能出不来了(⊙o⊙)哦
例Java:
public class TestRegex {
public static void main(String[] args) throws Exception {
String str ="BookName: \"我欲封天\",CategoryName: \"仙侠\", SubCategoryName: \"古典仙侠\"";
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 result = new ArrayList();
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(html);
while (matcher.find()) {
result.add(matcher.group());
}
return result;
}
}
}