收集一些常用的代码
 

RegEx: \d{1}{2}是什么意思

一个数字重复两次?

java运行如下:

String regex = "^\\d{1}{2}$"; // ^$ to make those not familiar with 'matches' happy

System.out.println("1".matches(regex)); // true

System.out.println("12".matches(regex)); // false

要想表达一个数字重重两次可以这样:

^(\\d{1}){2}$


而对于javascript

/\d{1}{2}/ 直接报错:SyntaxError: Invalid regular expression: /\d{1}{2}/: Nothing to repeat

原因是:Quantifiers must be preceded by a token that can be repeated


来个权威的引述:

IEEE-Standard 1003.1 says:

The behavior of multiple adjacent duplication symbols ( '*' and intervals) produces undefined results.


摘自StackOverflow

2013-09-25 /
标签: RegEx
 
评论
© 代码|Powered by LOFTER