我正在尝试生成一个正则表达式,其中:
- 数字可以从3,5,6或9开始
- 号码不能以999开头
因此,例如,93214211
被匹配,但是99912345
不应该被匹配。
这就是我现在所拥有的,它满足了第一个要求:
^3|^5|^6|^9|[^...]}
我在第二个要求上被卡住了一段时间。谢谢
您可以像一样使用negative lookahead
^(?!999)[3569]'d{7}$ <-- assuming the number to be of 8 digits
Regex演示
Regex细分
^ #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