+ 1

why does not this code pass 10 and 11 test cases of password validation?

I'm trying to solve password validation in code coach. it says it must at least contains two digits and two special characters. and the total length of string must at least be 7. I thought using regex should be a good option to solve this problem. but it does not pass 10 and 11 test cases. import re password = input() pattern = r"^(?=(.*\d){2})(?=.*[a-zA-Z])(?=(.*[!@#$%]){2,})[0-9a-zA-Z!@#&$%*]{7,}" if re.match(pattern, password): print("Strong") else: print("Weak")

13th Sep 2022, 9:33 AM
Elmira
4 odpowiedzi
+ 1
thanks Jayakrishna🇮🇳 I have changed my pattern to : ^(?=(.*\d){2})(?=(.*[!@#$%]){2,})[0-9a-zA-Z!@#&$%*]{7,} and it will consider your sample as "Strong". but even with this change, it doesn't pass 10 and 11 test cases.
13th Sep 2022, 1:51 PM
Elmira
+ 1
Total length should be atleast 7 so in which it must have at least 2 digits and 2 special characters. Means it must pass this types sample :ex: @#12345
13th Sep 2022, 12:20 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 oops, there was another error in my regex. I forgot to add '&' in one of my lookahead statements. after changes my pattern looks like this: pattern = r"^(?=(.*\d){2,})(?=(.*[!@#&$%*]){2,})[0-9a-zA-Z!@#&$%*]{7,}" thanks!
13th Sep 2022, 2:12 PM
Elmira
0
&* misses. yes. now It passes all. You're welcome..
13th Sep 2022, 2:23 PM
Jayakrishna 🇮🇳