[abc]?:匹配0个或者1个,但匹配“d”的时候,结果是false,而不是说匹配了0个返回true。匹配0个,相当于匹配了""空字符串。
public static void demo1() {
/*
* [abc]? : 匹配0个("")或者1个(a | b | c)
*/
String regex = "[abc]?";
//true
System.out.println("a".matches(regex));
System.out.println("b".matches(regex));
//false
System.out.println("bc".matches(regex));
System.out.println("d".matches(regex));
//true
System.out.println("".matches(regex));
}