Regex for strong password

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$/gm

Options
Matches

Examples

Note

Each lookahead checks one character class without consuming anything. Length matters more than classes: a long passphrase is stronger than a short mix.

Matches in the example

  • "Tr0ub4dor&3xyz"

Token by token

  1. ^ the start of the string (or line, with the m flag)
  2. (?= followed by (lookahead, not consumed)
  3. .* any character except a line break, zero or more times, as many as possible
  4. [a-z] one of: “a” to “z”
  5. ) end of group
  6. (?= followed by (lookahead, not consumed)
  7. .* any character except a line break, zero or more times, as many as possible
  8. [A-Z] one of: “A” to “Z”
  9. ) end of group
  10. (?= followed by (lookahead, not consumed)
  11. .* any character except a line break, zero or more times, as many as possible
  12. \d a digit (0–9)
  13. ) end of group
  14. (?= followed by (lookahead, not consumed)
  15. .* any character except a line break, zero or more times, as many as possible
  16. [^A-Za-z0-9] any character except “A” to “Z”, “a” to “z” or “0” to “9”
  17. ) end of group
  18. .{12,} any character except a line break, 12 or more times, as many as possible
  19. $ the end of the string (or line, with the m flag)

Other patterns