[英]pattern match with 2 middle number in java
I want third pattern ([0-9]{2}) should less than 10 or 10. I've also tried with [1-9]|0[0-9]|1[0-0] pattern instead of [0-9]{2} but unable to get the solution. 我希望第三个模式([0-9] {2})小于10或10。我也尝试过使用[1-9] | 0 [0-9] | 1 [0-0]模式而不是[ 0-9] {2},但无法获得解决方案。 I want result in following format: 012 550 10 0123456 01. 我想要以下格式的结果:012 550 10 0123456 01。
public static void main(String args[]){
System.out.println(Pattern.matches("[0-9]{3}[550]{3}[0-9]{2}[0-9]{6}[01]{2}", "8035501002499901"));
}
From your question it seems as if the pattern you want is this: 从您的问题看来,您想要的模式似乎是这样的:
[0-9]{3}
) 任何3位数字( [0-9]{3}
) 550
) - note that [550]{3}
would mean any sequence of 3 digits that are either 5 or 0, eg 005, 050, 555, etc. 550固定( 550
)-注意[550]{3}
表示3位数的任何5或0序列,例如005、050、555等。 (?:0[0-9]|10)
) 2位数字,应为0x或10( (?:0[0-9]|10)
) [0-9]{6}
) 任意6位数字( [0-9]{6}
) 01
) - [01]{2}
would mean any sequence of 2 digits that are either 0 or 1, eg 00, 01, 10 and 11 all would match 01固定( 01
)- [01]{2}
表示2位数字的任意序列,即0或1,例如00、01、10和11都将匹配 Thus the regex you'd need would be: 因此,您需要的正则表达式为:
[0-9]{3}550(?:0[0-9]|10)[0-9]{6}01
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.