我想要拿出一些正则表达式来匹配任何数量的数字组中的1个连字符。没有字符([a-z] [A-Z])。根据任意数量的数字组匹配1个连字符
123-356-129811231235123-1235612346123451235
/[^\d-]/g
的一个以上的将匹配下面的字符串,但它会让下面的经历:
1223--1235 --- 123123-- -----
我在看以下帖子How to match hyphens with Regular Expression?寻找答案,但我没有找到任何接近。
@Konrad鲁道夫给了一个很好的例子。
^\d(-\d|\d)*$
细分:
^ # match beginning of line
\d # match single digit
(-\d|\d)+ # match hyphen & digit or just a digit (0 or more times)
$ # match end of line
这使得
Regular expression to match 7-12 digits; may contain space or hyphen
此工具都不能启动不能用连字符是假设它为我http://www.gskinner.com/RegExr/
它可以用连字符开头吗? – 2013-03-07 21:54:39