0

Strong Password Regex — Lookahead Rules Explained

Debug JavaScript regular expressions live: highlighted matches, capture groups, flags, and replacement preview.

Supports $1, $2 and named references like $<name>; $& inserts the whole match. Leave empty to hide the preview.

Processing... 0%

Result

This page opens with a password-policy pattern built entirely from lookaheads: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9\s]).{8,}$. Each (?=…) is a zero-width check that scans the whole line without consuming it: one demands a lowercase letter, one an uppercase letter, one a digit, one a special character — and only then .{8,} enforces the minimum length.

The flags matter here: m makes ^ and $ anchor to each line instead of the whole text, and g finds every line that qualifies. That turns the tester into a checklist — the sample contains five candidate passwords, and only the lines satisfying all four lookaheads light up. See at a glance why password123 fails (no uppercase, no special character) while Tr0ub4dor&3 passes.

Lookaheads are the standard way to express "must contain X somewhere" conditions in a single expression, and this preset is a safe playground to learn them. Tighten the policy to 12+ characters, add a (?!.*(.)\1\1) check against triple repeats, or paste a list of real candidate passwords — every change re-evaluates instantly and nothing you type leaves your browser.