I'm trying to narrow the following regular expression:
/\b([0-9]{22})\b/
to only match 22 digit numbers that don't start with "91"
. Anyone know how to do this?
If your regexp engine has zero width negative lookahead, then:
/\b((?!91)[0-9]{22})\b/
(?!91)
causes the pattern to match only if the next two characters are not 91, but does not consume those characters, leaving them to be matched by [0-9]{22}
.
Many regexp engines also allow \d
for decimal digits. If yours does, then:
/\b((?!91)\d{22})\b/
Try this:
/\b(?:[0-8][0-9]|9[02-9])[0-9]{20}\b/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With