The only special char position that will match is the end of a password. If the special char is at the beginning, or anywhere other than the end, it will fail to match and reject the password.
import re
while True:
password = input("Please enter a password containing at least 6 letters, \n "
"one number, one capital letter, and at least one special character. ")
pattern = r"[A-Z]+?[A-Za-z]{6,}?[0-9]+?[^a-zA-Z0-9]+?"
if not re.search(pattern, password):
print("Please try again")
else:
print("Your new password is: ", password)
break
I would like to accept passwords that contain special chars and numbers anywhere in them, not just at the end, e.g.
@#$Chuckles23
Chuck#$les23
23Chuckles@#$
I've tried using regex code suggested in other answers, but so far none of them work for my scenario.