public static void main(String[] args) {
QQq();
}
public static void QQq()
{
String qq="1232435";
String regex="[1-9] [0-9]{4-14}";
boolean flag=qq.matches(regex);
if(flag)
System.out.println(qq+"......is ok");
else
System.out.println(qq+"..nono");
}
上述代码显示错误为:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed counted closure near index 13[1-9] [0-9]{4-14} ^ at java.util.regex.Pattern.error(Pattern.java:1713) at java.util.regex.Pattern.closure(Pattern.java:2759) at java.util.regex.Pattern.sequence(Pattern.java:1889) at java.util.regex.Pattern.expr(Pattern.java:1752) at java.util.regex.Pattern.compile(Pattern.java:1460) at java.util.regex.Pattern.<init>(Pattern.java:1133) at java.util.regex.Pattern.compile(Pattern.java:823) at java.util.regex.Pattern.matches(Pattern.java:928) at java.lang.String.matches(String.java:2090) at twentyfive.one3.QQq(one3.java:12) at twentyfive.one3.main(one3.java:6)