有人可以向我解释这个正则表达式模式吗?
在下面
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
究竟是什么
((?=.*\d)|(?=.*\W+))
&
(?![.\n])
谢谢你
最佳答案
这些都是先行断言(正面和负面),以确保以下文本遵守某些规则,而无需实际捕获文本。
# 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
(?! ... )
是负前瞻的语法(如果没有...则匹配),(?= ... )
用于积极的前瞻(如果有......则匹配)。这看起来很像密码验证!
关于正则表达式模式 - 什么是 ((?=.*\d)|(?=.*\W+)) 和 (?![.\n]),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21632713/