【发布时间】:2016-09-11 19:58:03
【问题描述】:
我正在尝试制作一个正则表达式,其中:
- 数字可以从 3、5、6 或 9 开始
- 号码不能以 999 开头。
例如,93214211 匹配,但 99912345 不应该匹配。
这是我现在满足第一个要求的:
^3|^5|^6|^9|[^...]}
我暂时停留在第二个要求上。 谢谢!
【问题讨论】:
-
99321421呢?
我正在尝试制作一个正则表达式,其中:
例如,93214211 匹配,但 99912345 不应该匹配。
这是我现在满足第一个要求的:
^3|^5|^6|^9|[^...]}
我暂时停留在第二个要求上。 谢谢!
【问题讨论】:
你可以用negative lookahead点赞
^(?!999)[3569]\d{7}$ <-- assuming the number to be of 8 digits
正则表达式分解
^ #Start of string
(?!999) #Negative lookahead. Asserts that its impossible to match 999 in beginning
[3569] #Match any of 3, 5, 6 or 9
\d{7} #Match 7 digits
$ #End of string
【讨论】:
^[3569]\d{2}(?<!9{3})\d{5}$。