Java Matcher对象中find()与matches()的区别
`find()`:字符串某个部分匹配上正则表达式就会返回true
`matches()`:字符串整体匹配上正则表达式才返回true
find():字符串某个部分匹配上正则表达式就会返回true
Pattern compile = Pattern.compile("[WASD][0-9]{1,2}");
System.out.println(compile.matcher("A1").find()); //true
System.out.println(compile.matcher("A12").find()); //true
System.out.println(compile.matcher("E12").find()); //false
System.out.println(compile.matcher("AE12").find()); //false
System.out.println(compile.matcher("AEA12").find()); //true
System.out.println(compile.matcher("AEA1A2").find()); //true
System.out.println(compile.matcher("AEA12444").find()); //true
matches():字符串整体匹配上正则表达式才返回true
Pattern compile = Pattern.compile("[WASD][0-9]{1,2}");
System.out.println(compile.matcher("A122").matches()); //false
System.out.println(compile.matcher("AA12").matches()); //false
System.out.println(compile.matcher("A12").matches()); //true
System.out.println(compile.matcher("A1").matches()); //true
System.out.println(compile.matcher("AA1").matches()); //false
System.out.println(compile.matcher("AA12").matches()); //falseSystem.out.println("A122".matches("[WASD][0-9]{1,2}")); // false
System.out.println("AA12".matches("[WASD][0-9]{1,2}")); // false
System.out.println("A12".matches("[WASD][0-9]{1,2}")); // true
System.out.println("A1".matches("[WASD][0-9]{1,2}")); // true
System.out.println("A1".matches("[WASD]{1,2}[0-9]{1,2}")); // true
System.out.println("A12".matches("[WASD]{1,2}[0-9]{1,2}")); // true
System.out.println("AA1".matches("[WASD]{1,2}[0-9]{1,2}")); // true
System.out.println("AA12".matches("[WASD]{1,2}[0-9]{1,2}")); // true