Regex for strong password
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{12,}$/gm
Matches
Examples
Note
Each lookahead checks one character class without consuming anything. Length matters more than classes: a long passphrase is stronger than a short mix.
Matches in the example
"Tr0ub4dor&3xyz"
Token by token
^the start of the string (or line, with the m flag)(?=followed by (lookahead, not consumed).*any character except a line break, zero or more times, as many as possible[a-z]one of: “a” to “z”)end of group(?=followed by (lookahead, not consumed).*any character except a line break, zero or more times, as many as possible[A-Z]one of: “A” to “Z”)end of group(?=followed by (lookahead, not consumed).*any character except a line break, zero or more times, as many as possible\da digit (0–9))end of group(?=followed by (lookahead, not consumed).*any character except a line break, zero or more times, as many as possible[^A-Za-z0-9]any character except “A” to “Z”, “a” to “z” or “0” to “9”)end of group.{12,}any character except a line break, 12 or more times, as many as possible$the end of the string (or line, with the m flag)
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma