I have a RegEx ^(?:(?:3[0-9][0-9]{6,9})|(?:0[1-9][0-9]{6,9}))$
which works fine. But I want to add an excision of a specific number: (?!(?:315678901))$
This works fine on its own. But combining the two messes the expression up.
Any ideas?
I was using it to include certain (Italian), phone numbers, but exclude one specific phone number.
2
Answers
You can combine the two expressions using a positive lookahead assertion (?!…) to exclude the specific number 315678901 from the original expression. The resulting regular expression would be:
^(?:(?!315678901)(?:3[0-9][0-9]{6,9})|(?:0[1-9][0-9]{6,9}))$
Use:
^(?!315678901$)(?:3d|0[1-9])d{6,9}$
Here
(?!315678901$)
filters out exactly315678901
and allows for other numbers matched by your expression. It also allows for numbers beginning with 315678901, but not 315678901.Also, I compacted your alteration group to
(?:3d|0[1-9])d{6,9}
Demo at regex101.