我想要一个正则表达式来检查:
密码只包含一个大写字符,包括至少一个特殊字符( #, @, - ),密码长度必须至少为8个符号!
#, @, -
(?=.[A-Z]{1}?)(?=.*[#@-])[A-Za-z#@-]{8,}
如何为密码包含 exactly 一个大写字符?
试试这个:
^(?=[^A-Z]*[A-Z][^A-Z]*$)(?=.*[#@-])[A-Za-z#@-]{8,}$
演示:https://regex101.com/r/Fr6znT/1
分解:
(?=[^A-Z]*[A-Z][^A-Z]*$)
^(?=(?=.*[@#-]{1,})[\S]{8,})([a-z@#-]*[@#-]*[A-Z][a-z@#-]*[@#-]*)$
https://regex101.com/r/v8Erhu/1
2 回答
试试这个:
演示:https://regex101.com/r/Fr6znT/1
分解:
(?=[^A-Z]*[A-Z][^A-Z]*$)
在该位置意味着:"The whole expression should be 'any number of non uppercase chars', followed by 'one uppercase char', followed by 'any number of non uppercase chars'" .试试这个:
https://regex101.com/r/v8Erhu/1