Regex string to find numbers not starting with 91
I'm trying to narrow the following regular expression:
/\b([0-9]{22})\b/
to only match 22 digit number开发者_C百科s 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/
精彩评论