要求从一个alpha开始 有个号码 有大小写的alpha和大写字母 有特殊的性格。 我的正则表达式几乎得到了这个:
^[a-zA-Z](?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[@#$_!%\*])([a-zA-Z0-9@#$_!%\*]+)
试图反对并且没有按预期通过
e2~Sertty
2e!Sertty
E2sertty
pers1234!
Apers1234! should work but does not
R4pers1234! same
Rtpers1234!
pApers1234! does work
TAers1234! works
想法?
**我现在删除了长度要求,但希望最小长度为8
答案 0 :(得分:2)
问题是您在前瞻之前首先匹配[a-zA-Z]
。
这应该有效:
/^(?=.*[a-z])(?=.*[A-Z])(?=\D*\d)(?=.*[@#$_%\*!])([a-zA-Z][\w@#$!%*]{7,})$/
答案 1 :(得分:1)
怎么样?
^[a-zA-Z](?=.*[a-zA-Z])(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[@#$_!%\*])([a-zA-Z0-9@#$_!%\*]+)
适合这些:
Apers1234! should work but does not
R4pers1234! same
Rtpers1234!