正则表达式的规则是:至少为8个字符,至少使用以下之一:(&%$ ^#@ =),至少有2个不在开头或结尾的数字NOR不能为在密码内彼此相邻,至少要有2个大写字母和2个小写字母。这是我到目前为止所拥有的。我想不出如何使正则表达式不在乎字符的顺序。我也想不出如何使整个东西需要8个字符。

/^[&%$^#@=]{1,}.[0-9(?!0-9)0-9(?!\s)]{2,}[A-Z]{2,}[a-z]{2,}$/;

最佳答案

这个正则表达式似乎有效

(?=^.{8,}$)(?!^\d)(?!.*\d$)(?!.+\d\d)(?=.*[&%$^#@=])(?=(.*[A-Z]){2})(?=(.*[a-z]){2})(?=(.*[0-9]){2})


Regex Demo

正则表达式分解

(?=^.{8,}$) #Positive look ahead to check whether there are at least 8 characters
(?!^\d) #Negative look ahead to check that string does not begin with a digit
(?!.*\d$) #Negative look ahead to check that string does not end with a digit
(?!.+\d\d) #Negative look ahead to check that string does not have two consecutive digits
(?=.*[&%$^#@=]) #Positive look ahead to check that string have at least any of the characters present in character class
(?=(.*[A-Z]){2}) #Positive look ahead to check that string contains at least two Upper Case characters
(?=(.*[a-z]){2}) #Positive look ahead to check that string contains at least two Lower Case characters
(?=(.*[0-9]){2}) #Positive look ahead to check that string contains at least two digits

09-11 13:52