This expression is password-authenticated

Source: Internet
Author: User
Tags expression engine

Ask for a regular expression that requires more than 8 lengths and must contain alphanumeric and special characters


To see this problem, the first impression is the application of standard regular expression reverse pre-search mechanism
But there are some logical windings.
To analyze, summarize the requirements as follows:
1. Must contain letters, that is, the number of letters in the characters >=1;
2. Must contain mathematics, that is, the number of characters among the numbers >=1;
3. Must contain special characters, that is, the number of special characters in the characters >=1;

This is what the theoretical needs are, but
Because we are thinking about using forward thinking, the regular expression engine is not very supportive in this respect.
So we have to change a way of thinking and try to think backwards:
Come to our new needs:
1. Not all math and special characters.
2. Cannot be full of characters and special characters.
3. Not all numbers plus letters.

This way of writing our ideas is clear.
The idea is now broadly clear. You can write your own handwriting expression.
Meet the above three conditions they are expressed separately as:
(? <! [!a-za-z])
(? <!\d)
(? <! [A-za-z0-9])
Together It is
(?:? <! (?: [^a-za-z]|\d| [a-za-z0-9]))

The key problem is solved, plus the number limit, the entire function is completed

^. {8,} (?:? <! (?: [^a-za-z]|\d| [a-za-z0-9])) $
Or
^(?! (?: [^a-za-z]|\d| [A-za-z0-9]) $). {8,}$


Information:

Greedy and lazy expressions (*,+)

Bit qualifier We can all use "greed" to describe, in other words, the regular expression engine will match as many characters as possible.
We can understand that when the regular expression engine encounters a duplicate match, it will start searching from left to right as long as the specific component of the expression allows it.
For example, \d*3 will match numbers until there are no more digits to match. After getting as many numbers as possible, the engine will try to match 3. If it is not found, or cannot be found immediately (because it already matches all numbers), remove a character from the last match and try again. The process repeats until it hits 3, and then goes on. As you can see from this example, the engine will first get as many characters as you want, and then when it can't match a character, it's time to release the character again and again, and you can see the workflow in it using regular expressions \ D*3, and tries to match in the string "123456789FGH".
First he will match all the numbers to 123456789, and then try to match to 3 from the left, so that a bit matches all of the previously matched numbers, does not match 3 is released, continues from right to left until matched to 3, so the final match is 123 but, The process is very tortuous. The computer is a fool ^ ^.

This expression is password-authenticated

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.