判断前面字符出现的次数,
/**
X? //X,一次或一次也没有
X* //X,零次或多次
X+ //X,一次或多次
X{n} //X,恰好 n 次
X{n,} //X,至少 n 次
X{n,m} // X,至少 n 次,但是不超过 m 次
*/
演示代码:
public static void main(String[] args) {
String regex = "[abc]{5,15}"; //表示[abc]至少出现5次,但不超过15次。
System.out.println("abcba".matches(regex));//5次,true
System.out.println("abcbaabcabbabab".matches(regex));//15次,true
System.out.println("abcb".matches(regex)); //4次,false
System.out.println("abcbaabaabcbaaba".matches(regex)); //16次,false
}