Text Processing
Positive Lookahead (Password)
Use positive lookahead `(?=...)` to require the password contain at least one digit and one uppercase letter.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^(?=.*\d)(?=.*[A-Z])[A-Za-z\d]{8,}$Raw source: ^(?=.*\d)(?=.*[A-Z])[A-Za-z\d]{8,}$
How it works
(?=.*\d) is a zero-width assertion that requires the rest of the string to contain a digit somewhere. (?=.*[A-Z]) similarly requires an uppercase letter. Neither consumes characters. [A-Za-z\d]{8,}$ then matches the actual password content (≥8 alphanumerics). Lookaheads are supported in JS and Python; Go's RE2 does NOT support them.
Examples
Input
Password1Matches
Password1
Input
weakpassNo match
—Input
ALLCAPSNODIGITNo match
—Common use cases
- •Password complexity enforcement
- •Form validation with multiple co-required tokens
- •Filename validation (must end with extension AND start with letter)
- •Compound-rule input filtering