为什么取反的时候中括号加与不加会产生不同的结果,请帮忙分析一下
public class Text_ZiFuLei {
public static void main(String[] args) {
System.out.println("以下两结果不同");
String regex1 = "[a-z&&^az]";
System.out.println("a".matches(regex1));
System.out.println("z".matches(regex1));
System.out.println("b".matches(regex1));
System.out.println("C".matches(regex1));
System.out.println("D".matches(regex1));
System.out.println("g".matches(regex1));
System.out.println("@".matches(regex1));
System.out.println("-------------------");
String regex2 = "[a-z&&[^az]]";
System.out.println("a".matches(regex2));
System.out.println("z".matches(regex2));
System.out.println("b".matches(regex2));
System.out.println("C".matches(regex2));
System.out.println("D".matches(regex2));
System.out.println("g".matches(regex2));
System.out.println("@".matches(regex2));
System.out.println("-------------------");
System.out.println("以下两结果相同");
String regex3 = "[a-z&&[az]]";
System.out.println("a".matches(regex3));
System.out.println("z".matches(regex3));
System.out.println("b".matches(regex3));
System.out.println("C".matches(regex3));
System.out.println("D".matches(regex3));
System.out.println("g".matches(regex3));
System.out.println("@".matches(regex3));
System.out.println("-------------------");
String regex4 = "[a-z&&az]";
System.out.println("a".matches(regex4));
System.out.println("z".matches(regex4));
System.out.println("b".matches(regex4));
System.out.println("C".matches(regex4));
System.out.println("D".matches(regex4));
System.out.println("g".matches(regex4));
System.out.println("@".matches(regex4));
}
} |
|