用示例对Java中的UNICODE_CASE字段进行模式化
启用支持Unicode的大小写折叠。
当将此值与CASE_INSENSITIVE标志一起用作compile()方法的标志值时,并且如果使用正则表达式搜索Unicode字符,则两种情况的Unicode字符都将匹配。
示例
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UNICODE_CASE_Example {
public static void main( String args[] ) {
String regex = "\u00de";
//Compiling the regular expression
Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE|Pattern.CASE_INSENSITIVE);
//Retrieving the matcher object
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 Þ