I didn't even think about it before. You can use the Regular Expressions to verify the complex format code, which can be used in the group structure of Regular expression for this purpose, such as the condition of the cipher:
- There is at least one digit
- At least one small English letter
- At least one big English letter
- String length between 6 ~ 30 letters
Then your Regular Expression can grow like this:
^ (? =.*\d) (? =.*[a-z]) (? =.*[a-z]). {6,30}$
What is noteworthy in this paragraph of Regular Expression is that the phrase " =.*\d ", which is called "right" (Positive Lookahead), has the same width as the right (or left-hand) language. 0, that is to say that this paragraph of the language is really not to occupy the comparison of characters, but just a Regular expression in a "sentence" only, right-like (Positive Lookahead) will be judged on the right side of the word is connected to the match, If the conditions are met, it will continue.
So the explanation in this section of the law is roughly as follows:
(? =.*\d) and (? =.*[a-z]) and (? =.*[a-z]) The width is zero, so the whole string is compared to. {6,30} is the master, but it will be judged by the difference between (? =.*\d) and (? =.*[a-z]) and (? =.*[a-z]) of these three judgments before they can be done. {6,30}. So (=.*\d). *\d is to say that the right side of the text must appear a number of characters, (? =.*[a-z]) of the. *[a-z] is to say that the right side of the text must appear a small letter, (? =.*[a-z]). *[a-z] It is said that the right side of the text must appear a size letter, the last to be compared. {6,30} that is, the length of the string must be 6 to 30 characters in any character.
If your condition changes to:
- There is at least one digit
- At least one big or small English letter
- There is at least one special symbol
- String length between 6 ~ 30 letters
Then your Regular Expression can grow this way (in C # for example):
New Regex (@ "^ (? =.*\d) (? =.*[a-za-z]) (? =.*\w). { 6,30}$ ");
Do you know how to make a consistent through this? ^_^
Connected
- Organize some of the Regex's learning resources
- Non-backtracking right-fits and left-fits
- Group Building structure
Using Regular Expression to verify password complexity