+ 2
Exercise 4.2 "Authentification" doesn't test correctly
import re password = "Gek1911" pattern = r"([A-Z])+([a-z])*([0-9])+" if re.search(pattern,password): print("Password created") else: print("Wrong format") Returns "password created" in test "lgh1411" when in other parsers returns "wrong format"
12 Answers
+ 1
"lgh1411" return "wrong format" with your code ^^
however, "lGh1411" or "Lgh1411x" both return "password created" but they shouldn't ;P
you must use 'fullmatch" to test if whole string fulfill the pattern (or add start and end anchors in your pattern) ;)
+ 1
“however, "lGh1411" or "Lgh1411x" both return "password created" but they shouldn't ;P”
Yes they should return “password created” as the assignment asks at least one capital letter and one number
+ 1
In lGh1411 the string Gh1411 matches the pattern similarly in Lgh1411x, the matching string is Lgh1411.
wrap your regex between ^ and $ which ensures that the input should definitely match the whole string
+ 1
it is referenced as 4.2 Practice "Authentification" for me (after the 4.1 Lesson "More Metacharacters")...
+ 1
That was the hardest practice so far in this course, waw
0
Mariano Belgrano 🇦🇷 I assumed that your regex was valid: start with 1 or more capital letter, followed by 0 or more lowercase letter, followed by 1 or more digit... wich could make sense, since you doesn't provide the full problem requirements...
0
The full problem requirement is published in python core curse. The parser which evaluates the code has a bug I guess since differs with other parsers. Please check it
0
is this the 4.2 practice?
if so, that's a 'pro' code coach, and I do not have access to it ^^
anyway, do you think we are smart enough to guess what is the code coach problem you're trying to do?
without providing accurate informations, you cannot expect get accurate answers ;P
0
I didn’t know it was not visible to everybody. My apologies. Bu the way as this forum is a shortcut inside the course now I realize is wide open to the entire platform
0
87.2 Authentication is the name of the exercise
- 1
The above pattern will match if you give a uppercase letters, lowecase letters, numbers in an order. otherwise it doesn't match.
if you want to validate a password, the easy way is to create different regexes and test with every regex
[a-z]+, [A-Z]+, [0-9]+
you can also have a one regex using look aheads, like this,
^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*()_+=|\><.,?/-])[A-Za-z0-9!@#$%^&*()_+=|\><.,?/-]{8,}$
which ensure that you have atleast one lower case, one uppercase, one number and one special character.
- 1
Here's what worked for me:
import re
password = input()
#your code goes here
pattern = r"([A-Z,0-9])+"
if re.match(pattern, password):
print("Password created")
else:
print("Wrong format")