The password of the regular expression (the test password is two or more of the lowercase letters, uppercase letters, numbers, special symbols)

Source: Internet
Author: User
Tags lowercase

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.