如题,需求:
需要判断一串纯数字类型的字符串是否已 20 21 22 23 24开头
用什么方法可以
String.startWith("20,21,22,23,24") 这样测试了下 不行
求大哥指点下
如题,需求:
需要判断一串纯数字类型的字符串是否已 20 21 22 23 24开头
用什么方法可以
String.startWith("20,21,22,23,24") 这样测试了下 不行
求大哥指点下
用正则
String regex = "2[0-4]\\d*";
System.out.println(Pattern.matches(regex, "20"));
System.out.println(Pattern.matches(regex, "201"));
System.out.println(Pattern.matches(regex, "20a"));
System.out.println(Pattern.matches(regex, "211"));
System.out.println(Pattern.matches(regex, "221"));
System.out.println(Pattern.matches(regex, "231"));
System.out.println(Pattern.matches(regex, "241"));
System.out.println(Pattern.matches(regex, "251"));