我想要拿出一些正則表達式來匹配任何數量的數字組中的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