After verification, @BodhiXuguang’s answer is incorrect. For example, hello123就能匹配, 但并不满足要求. 而且8 spaces can also be matched, but it does not meet the requirements, and you cannot add all special symbols.
Although (?=[a-zA-Z0-9_#@]+) can be added to ensure that the password will not contain special symbols other than those specified, there is still no guarantee that it must have three symbols.
Not all numbers/letters/special symbols, the result is as long as it contains more than 2 types of symbols.
In fact, this is not a regular question, please refer to similar questions
@BodhiXuguang’s idea is right. Just replace the negative lookahead with a positive lookahead and make some adjustments. (?=.d.)(?=.[a-zA-Z].)(?=.[_#@].).{8,}
I think this problem should not be solved with regular expressions. Each tool has its own scenarios that are very suitable for use. I think it is not suitable to use regular expressions to solve it in your scenario. Use a simple if statement to judge. The implementation is simple and the readability is very good. Why must we use regular expressions? ?
After verification, @BodhiXuguang’s answer is incorrect. For example,
8 spaces can also be matched, but it does not meet the requirements, and you cannot add all special symbols.
hello123
就能匹配, 但并不满足要求. 而且Although
(?=[a-zA-Z0-9_#@]+)
can be added to ensure that the password will not contain special symbols other than those specified, there is still no guarantee that it must have three symbols.Not all numbers/letters/special symbols, the result is as long as it contains more than 2 types of symbols.
In fact, this is not a regular question, please refer to similar questions
List all 6 situations
@BodhiXuguang’s idea is right. Just replace the negative lookahead with a positive lookahead and make some adjustments.
(?=.d.)(?=.[a-zA-Z].)(?=.[_#@].).{8,}
I think this problem should not be solved with regular expressions. Each tool has its own scenarios that are very suitable for use. I think it is not suitable to use regular expressions to solve it in your scenario. Use a simple if statement to judge. The implementation is simple and the readability is very good. Why must we use regular expressions? ?