请帮助我解码这个正则表达式,我是这个话题的新手,在试图分析哪些是它的有效输入时,我完全迷失了方向。
我们正在处理现有的应用程序,该模式用于密码验证。在分析代码时,我不得不确定该字段的有效输入。它的java应用程序。
^(?=(?:[a-zA-Z0-9@&*~!#$%]*[a-z]){2})(?=(?:[a-zA-Z0-9@&*~!#$%]*[A-Z]){2})(?=(?:[a-zA-Z0-9@&*~!#$%]*[@&*~!#$%]){2})(?=(?:[a-zA-Z0-9@&*~!#$%]*\d){2})[a-zA-Z0-9@&*~!#$%]{15}$非常感谢!
发布于 2014-03-04 12:40:45
[a-zA-Z0-9@&*~!#$%]是一个定义允许字符集的字符类。(?=开始的组是积极审视断言,它们确保一定的条件。所以你的判断力是:
^ # Matches the start of the string
(?=(?:[a-zA-Z0-9@&*~!#$%]*[a-z]){2}) # ensures two lowercase letters somewhere in the whole string
(?=(?:[a-zA-Z0-9@&*~!#$%]*[A-Z]){2}) # ensures two uppercase letters somewhere in the whole string
(?=(?:[a-zA-Z0-9@&*~!#$%]*[@&*~!#$%]){2}) # ensures two characters out of [@&*~!#$%] somewhere in the whole string
(?=(?:[a-zA-Z0-9@&*~!#$%]*\d){2}) # ensure two digits somewhere in the whole string
[a-zA-Z0-9@&*~!#$%]{15} # Matches exactly 15 character out of the set
$ # Matches the end of the string发布于 2014-03-04 12:40:17
此正则表达式将测试长度为15个字符的字符串,其中至少包含:
(?=(?:[a-zA-Z0-9@&*~!#$%]*[a-z]){2})(?=(?:[a-zA-Z0-9@&*~!#$%]*[A-Z]){2})@&*~!#$%字符2:(?=(?:[a-zA-Z0-9@&*~!#$%]*[@&*~!#$%]){2})(?=(?:[a-zA-Z0-9@&*~!#$%]*\d){2})应将其减少为:
^(?=(?:.*[a-z]){2})(?=(?:.*[A-Z]){2})(?=(?:.*[@&*~!#$%]){2})(?=(?:.*\d){2})[a-zA-Z0-9@&*~!#$%]{15}$发布于 2014-03-04 12:41:16
首先,杀了写这个的人。
其次,最好的方法是添加换行符和注释,将正则表达式分解为较小的部分。
^ // start of string
(?= // lookaround assertion
(?: // non-capturing group
[a-zA-Z0-9@&*~!#$%]*[a-z]
)
{2}
)
(?= // lookaround assertion
(?: // non-capturing group
[a-zA-Z0-9@&*~!#$%]*[A-Z]
)
{2} // exactly twice
)
<snip...>
$ // end of string继续添加新行、缩进和注释,您将得到该模式的完整图片。
https://stackoverflow.com/questions/22171997
复制相似问题