[/u4E00-/u9FA5]汉字﹐[/uFE30-/uFFA0]全角字符 [/u4E00-/u9FA5]汉字﹐[/uFE30-/uFFA0]全角字符所以说 ,Java的正则表达式是可以匹配中文字符的,同时,用中文字符来写表达式也是可以的.
正则表达式
public static void regxChinese(){
// 要匹配的字符串
String source = "<span title='5 星级酒店' class='dx dx5'>";
// 将上面要匹配的字符串转换成小写
// source = source.toLowerCase();
// 匹配的字符串的正则表达式
String reg_charset = "<span[^>]*?title=/'([0-9]*[//s|//S]*[/u4E00-/u9FA5]*)/'[//s|//S]*class=/'[a-z]*[//s|//S]*[a-z]*[0-9]*/'";
Pattern p = Pattern.compile(reg_charset);
Matcher m = p.matcher(source);
while (m.find()) {
System.out.println(m.group(1));
}
}
public static void regxChinese(){
// 要匹配的字符串
String source = "<span title='5 星级酒店' class='dx dx5'>";
// 将上面要匹配的字符串转换成小写
// source = source.toLowerCase();
// 匹配的字符串的正则表达式
String reg_charset = "<span[^>]*?title=/'([0-9]*[//s|//S]*[/u4E00-/u9FA5]*)/'[//s|//S]*class=/'[a-z]*[//s|//S]*[a-z]*[0-9]*/'";
Pattern p = Pattern.compile(reg_charset);
Matcher m = p.matcher(source);
while (m.find()) {
System.out.println(m.group(1));
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/10990.html