Regex for Password Strength

Regex that requires lowercase, uppercase, a digit and at least 8 characters, using lookaheads. Test passwords live and see why length matters most.

Part of the free Regex Tester. Runs in your browser — nothing is uploaded.

Regex for Password Strength

Lookaheads let one regex check several rules at once without caring about order. Each (?=...) asserts a requirement, and the final .{8,} enforces the length. Test sample passwords below.

Worked example: Passwords against the rule set

Pattern /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$/ — test strings

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

Passw0rdLong
shortA1
alllowercase1
NoDigitsHere
Correct-Horse-Battery-9

Result for each line

✓ match     Passw0rdLong
✗ no match  shortA1
✗ no match  alllowercase1
✗ no match  NoDigitsHere
✓ match     Correct-Horse-Battery-9

Practical tip

Current guidance (NIST) favors length over composition rules. Allow long passphrases, check against breached-password lists and avoid forced periodic changes.

How to use this Regex Tester

  1. 1Use the live tool above — it runs entirely in your browser and never uploads your data.
  2. 2Paste the sample from the worked example, or use your own input.
  3. 3Copy the result, then adapt the same steps in your editor, script, or pipeline.

Regex for Password Strength FAQs

What do the (?=...) groups do?

They are lookaheads: zero-width checks that the text ahead contains something, without consuming it, so many rules can apply at the same starting point.

Are complexity rules good security?

Less than people think. Longer passphrases and breach checking protect better than demanding symbols, which push users toward predictable patterns.

More Regex Tester pages

Open the full Regex Tester tool →