+ 3

Regex

I have this code. https://code.sololearn.com/cOqDxfao5JQx/?ref=app I want to make it valid if it consist atleast one Capital letter and 1 number. It works for AB1 but not for 1BA. Any idea ?

2nd Aug 2021, 3:14 AM
sid
sid - avatar
5 Respostas
+ 2
Your code checks for a letter followed by a digit. All you need to add is a check for a digit followed by a letter. To do that replace line 3 with the following: if re.search(r'([A-Z])+([0-9])+',password) or re.search(r'([0-9]+[A-Z]+', password):
2nd Aug 2021, 4:47 AM
Simon Sauter
Simon Sauter - avatar
+ 1
It looks for your variables order, you searched letter+digit
2nd Aug 2021, 4:32 AM
Dunaev Evgenii
Dunaev Evgenii - avatar
+ 1
With lookaround '(?=.*[A-Z])(?=.*[0-9])'
2nd Aug 2021, 10:56 AM
Romario
Romario - avatar
+ 1
It's late but is it what you were looking for? https://code.sololearn.com/cy7Eqxm56q0Z/?ref=app
13th Aug 2022, 7:18 AM
Mahad Ahmed
Mahad Ahmed - avatar
0
Dunaev Evgenii how to make it right if i want from both sides
2nd Aug 2021, 4:35 AM
sid
sid - avatar