开发者

Regex string to find numbers not starting with 91

开发者 https://www.devze.com 2023-03-06 11:55 出处:网络
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 engi

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/
0

精彩评论

暂无评论...
验证码 换一张
取 消