有人可以向我解释这个正则表达式吗?
下
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
究竟是什么
((?=.*\d)|(?=.*\W+))
&安培;
(?![.\n])
谢谢
答案 0 :(得分:3)
这些都是前瞻性断言(正面和负面),确保以下文本尊重某些规则而不实际捕获文本。
# assert that
(?=^.{8,}$) # there are at least 8 characters
( # and
(?=.*\d) # there is at least a digit
| # or
(?=.*\W+) # there is one or more "non word" characters (\W is equivalent to [^a-zA-Z0-9_])
) # and
(?![.\n]) # there is no . or newline and
(?=.*[A-Z]) # there is at least an upper case letter and
(?=.*[a-z]).*$ # there is at least a lower case letter
.*$ # in a string of any characters
(?! ... )
是否定前瞻的语法(如果没有,则匹配...),(?= ... )
用于正向前瞻(匹配,如果有...)。这看起来很像密码验证!
答案 1 :(得分:2)
这似乎是用于验证密码的RegEx。