I took a little and simplified the regular schedule from this answer :
import re pattern_password = re.compile(r'^(?=.*[0-9].*)(?=.*[az].*)(?=.*[AZ].*)[0-9a-zA-Z]{8,}$') print(bool(pattern_password.match('absghk4D'))) # True print(bool(pattern_password.match('abc123FF'))) # True print(bool(pattern_password.match('123ABCac'))) # True print(bool(pattern_password.match('abcFF123'))) # True print() print(bool(pattern_password.match('absghk4D $%#$'))) # False print(bool(pattern_password.match(''))) # False print(bool(pattern_password.match('bsghk4D'))) # False print(bool(pattern_password.match('abc_aaFF'))) # False print(bool(pattern_password.match('abcabcac'))) # False print(bool(pattern_password.match('ABCDF!@##'))) # False
Explanation of the regular season:
(?=.*[0-9]) - the string contains at least one number;(?=.*[az]) - the string contains at least one Latin lowercase letter;(?=.*[AZ]) - the string contains at least one Latin uppercase letter;[0-9a-zA-Z]{8,} - the string consists of at least 8 of the above characters.
To add support for special characters you need to include them in the last part of the regular season:
...[0-9a-zA-Z$%#^]{8,}$')
Then and
print(bool(pattern_password.match('$b#FF123'))) # True
absghk4D- Enikeyschik