正则表达式,匹配不超过9位正整数

时间:2022-03-15 07:10:53
System.out.println(Pattern.matches("(\\d{0,8}[1-9]{1})|(\\d{0,7}[1-9]{1}\\d{0,1})|(\\d{0,6}[1-9]{1}\\d{0,2})|(\\d{0,5}[1-9]{1}\\d{0,3})|(\\d{0,4}[1-9]{1}\\d{0,4})|(\\d{0,3}[1-9]{1}\\d{0,5})|(\\d{0,2}[1-9]{1}\\d{0,6})|(\\d{0,1}[1-9]{1}\\d{0,7})|([1-9]{1}\\d{0,8})", "999999999"));