TurantToolsdev</> All tools

Regex Lookaheads Explained With a Password Rule

One pattern for 12+ characters, a lowercase letter and a digit, tested on four inputs.

By the TurantTools Dev team · Updated October 27, 2026 · 2 min read

Lookaheads let one regex check several conditions at once without consuming characters. (?=...) means "what follows must match this", and the regex engine then goes back to where it started.

At least 12 characters, one lowercase letter and one digit

^(?=.*[a-z])(?=.*\d).{12,}$
InputResult
correcthorseNo match
correcthorse9Match
short9No match
ALLCAPS123456No match
  • Each (?=.*X) scans ahead for X anywhere in the string.
  • Negative lookahead (?!...) forbids something, such as spaces: (?!.*\s).
  • For user-facing rules, separate checks give clearer error messages than one clever regex.
Regex TesterTry lookaheads on your own text.

Sources we checked

More articles