I'm using regular expression to check/enforce a password requirement - minimum: 6 characters, max: 12 characters with a combination of numbers, alphabets and the specified special character.
import re
pswd = input('Please enter your password: ')
reg = re.compile(r'[A-Za-z0-9@#$]{6,12}')
mat = re.match(reg, pswd)
if mat:
print(f"{pswd} is a valid password.")
else:
print("Please check password requirements")
When I test 2We3345
it prints:
2We3345 is a valid password.
I am of the impression that .match requires the entire string to match the regex in its entirety. Am I missing something? I tried with the .search
method, but no dice.