我有一个手机号码字段,我想查看是否有 任何数字重复9次,包括零和if 任何仅由两个不同数字组成的电话号码或手机号码。
有没有正则表达式或其他什么可以做到这一点?
在葡萄牙,电话号码以2 ########开头,移动电话以91/92/93/96开头,两者都有9位数字。
答案 0 :(得分:3)
此正则表达式仅匹配9个以2或91,92,93,96
开头的后续数字^
(?:2\d|9[1236])
=字符串的开头
[0-9]{7}
= 2 +任何数字 OR 9跟随1,2,3或6
$
= 7个数字
C:\poppler-0.24.5\include\src
=字符串结尾
答案 1 :(得分:3)
试试这个正则表达式:
^(?:(?:(2)([013-9])|(9)([1236]))(?!(?:\1|\2){7})(?!(?:\3|\4){7})\d{7}|(?=2{2,7}([^2])(?!(?:2|\5)+\b))22\d{7})\b
解释
^ # from start
(?: # look at (?:...) as subsets
(?: #
(2)([013-9])|(9)([1236]) # store possible digits in groups \1 \2 \3 \4
) #
(?!(?:\1|\2){7}) # in front cannot repeat only \1 \2
(?!(?:\3|\4){7}) # neither only \3 \4
\d{7} # plus seven digits to complete nine
| # or
(?= # to avoid number repetitions:
2{2,7}([^2]) # in front should be possible to match
# the number 2 from 2 to seven times
# and another digit stored in \5
(?!(?:2|\5)+\b) # but not only them,
# so, should match another digit
# (not two or the \5) till the boundary
) #
22\d{7} # then, it refers to 22 and 7 digits = nine
)\b # confirm it don't overflows nine digits
希望它有所帮助。