0
Can anyone help in finding error in code?
https://www.sololearn.com/coach/76?ref=app import re pattern = re. compile(r"(?=^.{7,}$)(?=.*[A-Za-z]{2})(?=.*[0-9]{2})(?=.*[!@#$%&*]{2})") string =input() if pattern.match(string): print ("Strong") else: print("Weak") https://code.sololearn.com/c2bxisRGHRB0/?ref=app I can't find the error in the code for password validation, well it gives correct output but didn't pass all the test.
4 Respuestas
+ 4
A little late but I found the real problem, it is that the program in that way looks for the 2 special characters and numbers but >consecutively<, that is what gives the failure in the last case. The correct thing to do is to use parentheses to delimit the {2,}
import re
pattern = re. compile(r"(?=^.{7,}$)(?=(.*[0-9]){2})(?=(.*[!@#$%&*]){2})")
string =input()
if pattern.match(string):
print ("Strong")
else:
print("Weak")
+ 4
Remove all three regex {2}
+ 1
Thanku 😇
Can you explain it? Mariano Fregosi
+ 1
To be honest I think there is some problem with the cases and the regex, because in java it is exactly the same. If you test the code in the playground as you had, for example with "qwert&5" it will give you that is "weak" and it is fine, now without the regex it will give a "strong" false positive. Maybe there is another reason, but it is beyond my knowledge 😅