我正在制作一个正则表达式来验证密码,需符合以下条件:
我考虑让第一个和最后一个字符匹配,然后否定反向引用。我的问题在于如何否定这个反向引用。我在网上找了一些东西,但没有起作用。目前为止,我得到了以下内容:
Have at least 6 characters.
Only have alphanumeric characters.
Don't have the same initial and ending character.
我考虑让第一个和最后一个字符匹配,然后否定反向引用。我的问题在于如何否定这个反向引用。我在网上找了一些东西,但没有起作用。目前为止,我得到了以下内容:
([\w])[\w]{3}[\w]+\1 //Generates a password with at least 6 chars in which the first and final characters match
{3}
应该是{3,}
或者甚至是{4,}
(你可以移除最后的[\w]
)。此外,你无需将\w
放在方括号内,因为它会允许非字母数字字符(在这种情况下,是下划线_
)。 - David Faber