How the pattern works
| Part | Meaning |
|---|---|
(?=.*[a-z]) | Lookahead: at least one lower-case letter somewhere |
(?=.*[A-Z]) | At least one upper-case letter |
(?=.*\d) | At least one digit |
(?=.*[^A-Za-z0-9]) | At least one symbol |
.{8,} | Eight or more characters in total |
Code examples
JavaScript
const re = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/;
re.test(value); // true or falsePython
import re
bool(re.fullmatch(r'(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}', value))PHP
preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/', $value) === 1;
Notes and limitations
Each lookahead checks one rule without consuming characters, so the rules can appear in any order. Current NIST guidance favors length (15+ characters) and a check against breached passwords over composition rules — consider a length-only rule plus a strength meter. Generate one with the Password Generator.