-1

I try to write a simple Regular Expression that checks for the following conditions:

  • At least six characters long
  • contains a lowercase letter
  • contains an uppercase letter
  • contains a number

I tried to work like this:

regex = re.compile(r'''([0-9])+([A-Z])+([a-z])+.{6,}''')

I found a lot of similar threads, but I would like to know why exactly mine is not working as I intend it too. As I am still new to programming and regex in general I apologize if I missed some trivial stuff right here.

Thanks for the help!

Mxngls
  • 437
  • 1
  • 5
  • 16
  • 1
    Did you try lookahead assertions? See https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a – The fourth bird Jun 11 '20 at 09:06
  • 2
    With your approach you must have at least one digit at the start of your password, followed by an uppercase character and so on. So `"A1xxxx"` won't work. Use lookahead assertions like @Thefourthbird said. – Matthias Jun 11 '20 at 09:08
  • Thanks! Got it now! – Mxngls Jun 11 '20 at 09:11

1 Answers1

0

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,}$