由网友(恋爱中男女朋友的)分享简介:什么是正确的regex,以满足以下密码标准:What would be the correct regex, to satisfy the following password criteria:必须包含至少 1 个小写字母.必须包含至少 1 个大写字母.必须包含至少 1 个数字.必须包含至少 1 个特殊字符(仅允...
什么是正确的regex
,以满足以下密码标准:
What would be the correct regex
, to satisfy the following password criteria:
!#%
).不得包含除 A-Za-z0-9!#%
之外的任何其他字符(例如,不得包含 ;
).长度必须为 8 到 32 个字符.
Must include at least 1 lower-case letter.
Must include at least 1 upper-case letter.
Must include at least 1 number.
Must include at least 1 special character (only the following special characters are allowed: !#%
).
Must NOT include any other characters then A-Za-z0-9!#%
(must not include ;
for example).
Must be from 8 to 32 characters long.
这是我尝试过的,但它不起作用:
This is what i tried, but it doesn't work:
^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[!#@$%&/()=?*-+-_.:;,][{}^]).{8,32}
但应该是:
^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[!#@$%&/()=?*-+-_.:;,][{}^])[A-Za-z0-9!#%]{8,32}
但无论如何,Unihedron 的解决方案更好,只是想为将来会阅读此问题的用户提及这一点.:)
But Unihedron's solution is better anyways, just wanted to mention this for the users which will read this question in the future. :)
Unihedron 的解决方案(也可以在下面的他的答案中找到,我自己复制了它,以防他在他的答案中更改(将其更新为更好的版本)):
Unihedron's solution (can also be found in his answer below, i copied it for myself, just in case he changes (updates it to an better version) it in his answer):
^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=D*d)(?=.*?[!#%])[A-Za-z0-9!#%]{8,32}$
我最终得到了以下 regex
:
^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=D*d)(?=.*?[!#@$%&/()=?*-+-_.:;,][{}^])[A-Za-z0-9!#@$%&/()=?*-+-_.:;,][{}^]{8,60}$
再次感谢 Unihedron 和 skamazin.赞赏!
Thanks again Unihedron and skamazin. Appreciated!
推荐答案
使用这个正则表达式:
/^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=D*d)(?=[^!#%]*[!#%])[A-Za-z0-9!#%]{8,32}$/
这是一个正则表达式演示!
了解更多:
正则表达式表示某些单词的顺序无关紧要相关推荐
最新文章