The password regex tester is a free tool that lets you paste a regex rule, type a few sample passwords and see which ones pass. You learn what your rule really enforces before it ships, which matters because a loose rule gives a signup form weak protection while a strict one locks out honest users. Every input gets a clear true or false answer.
Test a pattern with the password regex tester
Type your pattern into the pattern field, then add the flags you need: i makes the match case-insensitive, g turns on a global search and m switches to multiline mode. When the syntax is broken, the field turns red and shows an error message, which makes debugging quick.
Next, enter up to three sample passwords as plain text. Each string turns green when it matches and red when it does not, and the matched part is highlighted so you can see what the rule actually caught. Because the regex checker runs in your browser, nothing you type leaves the page, including any code or real credentials you paste by accident.
Read the result row by row. A green row with highlighting on the whole string means the rule accepts it end to end. A green row with only part highlighted means an anchor is missing, so the rule found a valid piece inside a longer value. A red row is not always a bad rule: the value may simply break one requirement, and trimming the rule one check at a time shows which one.
Regular expression for a strong password
A password regex works best when every requirement is its own check. The expression below describes a strong password as one with at least one lowercase letter, one uppercase letter, one digit and one symbol. A common baseline is a minimum eight characters, but this example raises it to ten: Before an audit, the pci dss password compliance checker helps document policy settings for systems in the cardholder data environment.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{10,}$| Token | What it enforces |
|---|---|
^ and $ | The match must cover the whole string, from start to end |
(?=.*[a-z]) | At least one lowercase character |
(?=.*[A-Z]) | At least one uppercase character |
(?=.*\d) | At least one digit |
(?=.*[^\w\s]) | One symbol that is not a letter, digit or space |
.{10,} | Ten or more characters in total |
Three test inputs show the rule at work. Harbor-Lantern42 passes because it has all four character types and sixteen characters. harborlantern42 fails, since it has no capital and no symbol, and Tide#7 fails on length with only six. Together these requirements make a compact password validation rule you can read in a few seconds.
Tuning the length shows how sensitive the rule is. Ocean$Fig91 has eleven characters, so it clears {10,} but fails once you change it to {12,}, while Harbor-Lantern42 survives both. When you adopt a password regular expression for production, run a few borderline strings like this one at every limit, because off-by-one errors in the length rule are the most common surprise.
Validate special character and digit rules
To validate a special character, [^\w\s] accepts anything that is not a letter, number, underscore or space, so it covers symbols you never listed. The digit rule uses \d, which matches any numeric character from 0 to 9. If you list symbols by hand instead, remember that a dash inside a class needs an escape or must sit last.
Uppercase letter and lowercase letter lookaheads
Each lookahead scans the whole string without consuming it, so the order of the checks does not matter. Delete one lookahead and only that requirement disappears, while the others keep working. In the tester, remove one check and rerun Harbor-Lantern42 to see only that requirement stop being enforced.
Regex checker flags and capture group output
Wrap part of a pattern in parentheses and the tester lists each capture group with what it caught. A non-capturing group, written (?:...), groups text without storing it, which keeps the output short. Metacharacters such as . and * carry special meaning unless you escape them, and a lookbehind such as (?<=@) checks what comes before a position. To check many values at once, paste the whole list into the batch field and read one result per line.
Match anchors, quantifiers and character classes
Anchors pin a match to the start of line and end of line. Quantifiers such as {10,} set how often to repeat, and character classes like [a-z] list which characters are allowed. In the password rule, the anchors make the tester highlight the whole string, and {10,} is the length check.
Checking a 12-character rule in a regex checker
Dara, who maintains an internal admin portal, has to move the signup rule from ten to twelve characters before an audit on Friday, and wants proof that nobody gets locked out by accident. She opens the password regex tester, pastes ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{12,}$ and enters three real-looking strings: Cedar!Mill58, cedar!mill58 and Cedar!Mill5.
The first row turns green with all twelve characters highlighted. The second goes red because it has no capital letter, and the third goes red at eleven characters, so the length rule is doing exactly what she wrote. That is the answer she needed: Cedar!Mill58 is the shortest string the new rule accepts, which also lines up with the 8-character floor in NIST SP 800-63B because she is well above it.
Then she reruns one input. Changing {12,} to {14,} flips Cedar!Mill58 to red while Mill#Brook-4417-Lamp, at twenty characters, stays green. The number to watch is the shortest accepted string, because that is what most users will type.
The edge case comes next. She tries the passphrase Cedar Mill 58 x, fifteen characters, and it fails: spaces are excluded from the symbol class, so a long, genuinely strong phrase is rejected. Her fix is to change [^\w\s] to [^\w] for the symbol check, then rerun all four strings before shipping. The tester settles the pattern, but a human still decides whether the policy is fair. She keeps the four strings as a standing list, so the next rule change starts with a ready-made set of checks.
What a regexp password check cannot catch
A regexp only checks shape, never entropy. Password1! passes the rule above, yet it sits among the commonly used passwords that brute force attacks try first, so it is a weak password in practice. Treat the pattern as a first filter, then add a blocklist lookup and rate limiting on the login function.
You can also accept a shorter string with only two character types and label it medium strength, so people see why a stronger choice helps. Try that looser rule in the tester to see which strings land in the middle tier. For real security, the rule is one layer, not the whole defence.
Mistakes that break a rule
These are the mistakes the tester exposes most often. Leaving off the anchors lets a short valid fragment slip through inside a longer value. Writing \d inside a quoted string needs a doubled backslash, or the engine reads it as a plain letter. Nested repeats such as (a+)+ can freeze a page on long input because the engine backtracks through every split. And [a-z] ignores accented letters, so decide early whether names and phrases from other languages should be accepted. Each of these mistakes shows up in the tester as a row that is green when it should be red, or the reverse, so paste one deliberately bad value for every requirement you add to the password check.
Test password strength in JavaScript
A developer can drop the same expression into JavaScript, where rule.test() returns true or false:
const rule = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{10,}$/;
function checkPassword(value) { return rule.test(value); }
checkPassword("Harbor-Lantern42"); // true
checkPassword("Tide#7"); // falsePython and PHP accept the same lookahead syntax, so regular expressions tested here port over with little change. Always repeat the check on the server, because a browser rule only guides honest users. The same approach also suits other formats, such as email addresses or analytics filters.
Frequently Asked Questions
- Why does my regex say it's invalid?
- JavaScript's regex engine will reject patterns with unbalanced parentheses/brackets, invalid quantifiers, or unsupported syntax from other regex flavors (like PCRE-specific features). The error message shown comes directly from the browser's own regex parser and usually points at what's wrong.
- What do the i, m, and u flags do?
- 'i' makes the match case-insensitive (A matches a). 'm' changes how ^ and $ behave with multi-line input (rarely needed for single-line passwords). 'u' enables full Unicode mode, which matters if your pattern or samples include characters outside the basic ASCII range (like emoji or accented letters) and you're using Unicode property escapes.
- Can I test a regex meant for Python or PHP here?
- Mostly -- core regex syntax (character classes, quantifiers, lookaheads) is shared across languages, so a pattern will usually behave identically. Watch for flavor-specific features: Python's regex module supports some syntax JavaScript doesn't, and PCRE (PHP) has its own extensions -- if a pattern fails to parse here but works in your language, that's likely why.
- Does pasting my real passwords here send them anywhere?
- No -- matching happens entirely in your browser using JavaScript's built-in RegExp engine. Nothing you type is transmitted, logged, or stored. That said, prefer representative dummy values over real credentials when testing, as a general habit.
- How do I build a regex from scratch instead of testing an existing one?
- Use the Password Validation Regex Builder instead -- set your length and character-class requirements there and it generates the pattern for you, which you can then paste in here to test against real sample values.