Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for strong password
Regex pattern · validation

Regex for strong password

Regex for strong password: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/ as a strong password regex. It matches "Passw0rd!" and "S3cure#Pass", and rejects "password" and "Password1". NIST SP 800-63B recommends length (8+, ideally 15+ for single-factor) and checking against breached-password lists over composition rules.

Last updated · Maintained by FreeAIToolz · How we test

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/
  • Passw0rd!matches
  • S3cure#Passmatches
  • xY9$abcdmatches
  • passwordno match
  • Password1no match
  • PASSWORD1!no match
  • Pa1!no match
  • passw0rd!no match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
(?=.*[a-z])lookahead: at least one lowercase letter
(?=.*[A-Z])at least one uppercase letter
(?=.*\d)at least one digit
(?=.*[^A-Za-z0-9])at least one symbol
.{8,}$at least 8 characters

Examples

InputResult
Passw0rd!✓ Matches
S3cure#Pass✓ Matches
xY9$abcd✓ Matches
password✗ No match
Password1✗ No match
PASSWORD1!✗ No match
Pa1!✗ No match
passw0rd!✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

NIST SP 800-63B recommends length (8+, ideally 15+ for single-factor) and checking against breached-password lists over composition rules. Consider a minimum length plus a breach check instead.

When to use this pattern

Password rules in sign-up forms where policy requires mixed character types.

Use it in your language

JavaScript

const re = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[^A-Za-z0-9]).{8,}$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[^A-Za-z0-9]).{8,}$");
boolean ok = pattern.matcher(value).find();

Go’s regexp package (RE2) does not support lookahead or lookbehind, so this exact pattern will not compile in Go.

More regex patterns

Frequently asked questions

What is the regex for strong password?
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/. NIST SP 800-63B recommends length (8+, ideally 15+ for single-factor) and checking against breached-password lists over composition rules. Consider a minimum length plus a breach check instead.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It does not work in Go, because RE2 has no lookaround support.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abcPassw0rd!xyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.