breakitdown

Regex for a strong password (and why length matters more)

Answer

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$ requires a lowercase letter, an uppercase letter, a digit, a symbol, and at least 12 characters. NIST's current guidance says not to impose character-type rules at all. Require length and reject known-breached passwords instead.

flags: g all matches · i ignore case · m ^ $ per line · s . matches newlines · u Unicode

JavaScript ✓PCRE ✓

No catastrophic-backtracking patterns found. (A heuristic check: nested and adjacent repeats, overlapping alternatives.)

  1. ^Start of the stringanchor
  2. (?=…)Lookahead: the text that follows must match this, but it is not consumedlookaround
  3. .Any character except a line breakcharacter type
  4. *Repeat it zero or more times, as many as possible (greedy)quantifier
  5. [a-z]One character: a-z (lowercase letters)character class
  6. (?=…)Lookahead: the text that follows must match this, but it is not consumedlookaround
  7. .Any character except a line breakcharacter type
  8. *Repeat it zero or more times, as many as possible (greedy)quantifier
  9. [A-Z]One character: A-Z (uppercase letters)character class
  10. (?=…)Lookahead: the text that follows must match this, but it is not consumedlookaround
  11. .Any character except a line breakcharacter type
  12. *Repeat it zero or more times, as many as possible (greedy)quantifier
  13. \dA digit (0-9)character type
  14. (?=…)Lookahead: the text that follows must match this, but it is not consumedlookaround
  15. .Any character except a line breakcharacter type
  16. *Repeat it zero or more times, as many as possible (greedy)quantifier
  17. [^A-Za-z0-9]Any one character except A-Z (uppercase letters), a-z (lowercase letters) and 0-9 (digits)character class
  18. .Any character except a line breakcharacter type
  19. {12,}Repeat it 12 or more times, as many as possible (greedy)quantifier
  20. $End of the stringanchor

Examples

Checked at build time in JavaScript and in Python's re.

InputMatches?
Tr0ub4dor&3xx✓ match
Password123!✓ match
correct horse battery staple✗ no match
Sh0rt!✗ no match
alllowercase1!✗ no match
NoDigitsHere!!✗ no match
NoSymbols12345✗ no match
Ünïcödé123!xyz✗ no match

Try your own text

One string per line: each line is tested on its own (the m flag is added here).

How it works

Each (?=.*X) is a lookahead. It scans ahead from the start for an X without consuming anything, so the engine is back at position 0 for the next check. The four lookaheads are four independent conditions. The final .{12,} does the actual matching and enforces the length.

NIST SP 800-63B is the US federal guideline on passwords. Since its 2017 edition it has advised against composition rules, because people meet them in predictable ways: Password1! passes this regex. Revision 4, finalized in 2025, makes that a requirement (verifiers SHALL NOT impose such rules). It asks for a minimum of 15 characters when the password is the only factor, 8 when it is used with multi-factor authentication, and a maximum of at least 64. It also requires checking new passwords against a list of known-compromised ones.

Variants

Gotchas

Related explainers

← Explain any regular expression