What could be the regular expression to have at least 10 digits, 12 uppercase letter and 10 lowercase letters?
什么是正则表达式至少有10个数字,12个大写字母和10个小写字母?
The string can start with any of the above and could be randomly placed. For example, AB12jgGGfWisLWfoi34R32SgD42DSf3453jfh
.
字符串可以从上面的任何一个开始,可以随机放置。例如,AB12jgGGfWisLWfoi34R32SgD42DSf3453jfh。
I used (?=.*\\d.*\\d)(?![.\\n])(?=.*[A-Z].*[A-Z])(?=.*[a-z].*[a-z]).*$
This is what I used for at least two uppercase, two lowercase and two digits. But adding 10 redundant \\d
's in the expression above doesn't seem a good practice.
我用(?=。* \\ d。* \\ d)(?![。\\ n])(?=。* [AZ]。* [AZ])(?=。* [az]。* [az])。* $这是我用于至少两个大写,两个小写和两个数字的东西。但是在上面的表达式中添加10个冗余的\\ d's似乎不是一个好习惯。
Moreoever, using \\d{10}
doesn't work as if we expect consecutive 10 digits.
但是,使用\\ d {10}并不像我们期望的那样连续10位数。
1 个解决方案
#1
6
You can use this regex:
你可以使用这个正则表达式:
^(?=(.*?\d){10})(?=(.*?[A-Z]){12})(?=(.*?[a-z]){10})[a-zA-Z0-9]+$
RegEx演示
Or even better performing regex:
甚至更好的表现正则表达式:
^(?=(?:\D*\d){10})(?=(?:[^A-Z]*[A-Z]){12})(?=(?:[^a-z]*[a-z]){10})[a-zA-Z0-9]+$
This is because negation pattern works better than lazy quantifier .*?
(thanks to @nhahtdh).
这是因为否定模式比懒惰量词更有效。*? (感谢@nhahtdh)。
#1
6
You can use this regex:
你可以使用这个正则表达式:
^(?=(.*?\d){10})(?=(.*?[A-Z]){12})(?=(.*?[a-z]){10})[a-zA-Z0-9]+$
RegEx演示
Or even better performing regex:
甚至更好的表现正则表达式:
^(?=(?:\D*\d){10})(?=(?:[^A-Z]*[A-Z]){12})(?=(?:[^a-z]*[a-z]){10})[a-zA-Z0-9]+$
This is because negation pattern works better than lazy quantifier .*?
(thanks to @nhahtdh).
这是因为否定模式比懒惰量词更有效。*? (感谢@nhahtdh)。