1

My question stems from an old one (link): RegEx to make sure that the string contains at least one lower case char, upper case char, digit and symbol

I've been playing around with REGEX/PYTHEX and stumbled upon this I could not figure out. How do we make it so 3 of the 4 categories are satisfied instead of all four? Would it be possible to use only regular expressions?

Just to re-iterate, the REGEX aforementioned is: (?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W)

Contains ALL of the following: At least 1 Digit, At least 1 Lowercase, At least 1 Uppercase, At least 1 Special character

INTO

Contains 3 AT LEAST of the following: At least 1 Digit, At least 1 Lowercase, At least 1 Uppercase, At least 1 Special character

Lock
  • 11
  • 2
  • You can sort the string and then do `r'(?:\W+\d+[A-Z]+)|(?:\W+\d+[a-z]+)|(?:\W+[A-Z]+[a-z]+)|(?:\d+[A-Z]+[a-z]+)'` but it's ugly solution. – Andrej Kesely Dec 08 '19 at 00:54
  • Match one condition and use lookaheads for the remaining three conditions. Yes, ugly maybe? [`^(?=(?:\D*\d){3})(?=(?:[^a-z]*[a-z]){3})(?=(?:[^A-Z]*[A-Z]){3})(?:\w*\W){3}`](https://regex101.com/r/G6kq4Z/1/) – bobble bubble Dec 08 '19 at 09:49

0 Answers0