Reputation: 117
I have a regex which authorized all phone number in the format :
0nxxxxxxxx with n between 1-9 and 8 times x between 0-9
My regex is
0[1-9][0-9]{8}
Now, I want to exclude the number which begin by 0590xxxxxx. So, for example
0123456789 => true
... => true
0590123456 => false
How can I modify my regex to do this ?
Upvotes: 0
Views: 65
Reputation: 13640
Just add negative lookahead (?!0590)
before your pattern:
(?!0590)0[1-9][0-9]{8}
See RegexStorm Demo
Improvements:
^
and end $
anchors if you want to avoid matches like abc0123456789abc
or use word boundaries \b
[0-9]
with \d
Improved regex:
^(?!0590)0[1-9]\d{8}$
Upvotes: 1