^(?=(?:.*[^\\p{L}\\d]){8,})(?=(?:.*\\d){8,})
如果非字母不能是数字
^(?=(?:.*\\P{L}){8,})(?=(?:.*\\d){8,})
如果不信可以是数字
编辑:评论/排除的空格修改/x
如果非字母不能是一个数字
^ # beginning of string
(?= # Start look ahead assertion (consumes no characters)
(?: # Start non-capture group
.* # 0 or more anychar (will backtrack to match next char)
[^\pL\d] # character: not a unicode letter nor a digit
){8,} # End group, do group 8 or more times
) # End of look ahead assertion
(?= # Start new look ahead (from beginning of string)
(?: # Start grouping
.* # 0 or more anychar (backtracks to match next char)
\d # a digit
){8,} # End group, do 8 or more times (can be {8,}? to minimize match)
) # End of look ahead
如果非字母可以是数字
^ # Same form as above (except where noted)
(?= # ""
(?: # ""
.*
\PL # character: not a unicode letter
){8,}
)
(?=
(?:
.*
\d
){8,}
)
来源
2011-03-11 16:24:36
sln
一个正则表达式匹配的电话号码是非常棘手的。你最好写个扫描仪/解析器来做这件事。您将获得更好的覆盖率和更少的误报。 – 2011-03-11 16:14:35
如果你有一个可以通过使用正则表达式解决的问题,你现在有两个问题:) – DaveH 2011-03-11 16:16:09