0

I have this regex to test for password complexity (It's only for learning, I know to use readily available libraries and modules for production)

I want it to have at least 1+ upper case, 1+ lower case, 1+ digit, 1+ special char, and min length is 8. I have this so far.

((?=.*[A-Z]{1,})(?=.*\d{1,})(?=.*[^A-Za-z0-9]{1,})(?=.*[a-z]{1,})){8,}

But this doesn't match my password

zaq1@WSX

Here's the like to regex101

What am I missing?

Alex Ironside
  • 4,658
  • 11
  • 59
  • 119
  • You surely missed a dot before `{8,}` and quantified the lookaheads. Also, add anchors. See the answers in the linked thread. – Wiktor Stribiżew Mar 31 '20 at 09:05
  • Why do I need the `.`? I read the linked question before, I got most of my understanding of this issue from there but missed the dot – Alex Ironside Mar 31 '20 at 09:07
  • @WiktorStribiżew also why do I need anchors here? I just want the values to be there, don't really care what's first and last – Alex Ironside Mar 31 '20 at 09:10
  • They ensure matching the whole string. Not the order of the checks, or patterns. You need to match and consume the string, so you need to use a `.` in the consuming pattern. You can't quantify non-consuming patterns (lookaheads here) – Wiktor Stribiżew Mar 31 '20 at 09:16

0 Answers0