Reprint Address: http://blog.csdn.net/a1023824314/article/details/51989132
background:The company's new system needs to implement a registration function, you need to write a regular expression to verify whether a password contains lowercase letters, uppercase letters, numbers, special symbols of two or more
Answer:[Java]View plain copy ^ (?!) [a-z]+$] (?!) [a-z]+$] (?!) \d+$) (?! [\w_]+$) \s{6,16}$
parsing: first, separately look at the meaning of each small part of this regular expression(1) (?! [a-z]+$] a-z+$ means from the current position to the end is all capitals! [A-Z]+$ means matching strings that are not all uppercase letters (...). [a-z+$] means that if you start at the current match to the end of a string that is not all uppercase, match it, otherwise the matching position remains unchanged and the next matching expression is executed. A Lezilai said: There is a string ABCDEFG if the ^ (?!) [a-z]+$] ABC to match this string, then the process is such 1 First use (?!) [a-z+$]) To match it, the matching position is from a to the beginning of a scan to the end of G, found that this string is all made up of capital letters, does not conform to the rules, do not match it, back to a go, and then perform the ABC match, finally output ABC (2) (?!). [a-z]+$) with the above example, there is no need to elaborate, this means that the matching is not all lowercase letters composed of strings (3) (?!). [\d+$]) A string that matches not all numbers (4) (?!) \w+$) matches a string that is not entirely a special character (5) \s{6,16} matches any visible character string, and the length is 6 to 16.Two, together lookAfter analyzing the meaning of each of the small expressions above, we connect the expressions to see, meaning, match a not all uppercase, not all lowercase letters, not all numbers, not all special character strings, and this string is all visible characters, and string length of 6 to 16 bits (\s{ 6,16}). So the only way to satisfy this requirement is to have two or more strings that contain lowercase letters, uppercase letters, numbers, and special symbols.