启用Unicode版本的预定义字符类和POSIX字符类。
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UNICODE_CHARACTER_CLASS_Example {
public static void main( String args[] ) {
String regex = "\u00de";
//编译正则表达式
Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CHARACTER_CLASS);
//检索匹配器对象
String str[] = {"\u00de", "\u00fe", "\u00ee", "\u00ce"};
for (String ele : str) {
Matcher matcher = pattern.matcher(ele);
if(matcher.matches()) {
System.out.println(ele+" is a match for "+regex);
} else {
System.out.println(ele+" is not a match for "+regex);
}
}
}
}输出结果
Þ is a match for Þ þ is a match for Þ î is not a match for Þ Î is not a match for Þ