50,523
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void main(String[] args) {
String str = "114";
System.out.println(str.matches("^(0|114)"));
}
}
String str = "0s14dfd22";
Pattern p = Pattern.compile("[^0,114]+");
Matcher m = p.matcher(str);
while(m.find()) {
System.err.println(m.group());
}
String regex = "^(" +
"[1-9]" + // 个
"|" +
"[1-9]\\d" + // 十
"|" +
"[1-9]\\d{3,}" + // 千以上
"|" +
"[2-9]\\d{2}" + // 2xx-9xx
"|" +
"1[02-9]\\d" + // 10x,12x-19x
"|" +
"11[0-35-9]" + // 110-113,115-119
")$";
for (int i = 0; i < 10000; i++) {
String str = i+"";
if (!str.matches(regex) && i != 0 && i != 114) {
throw new Exception(str);
}
}