^(?=(?:.*[^\\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