Regex Tester
Test JavaScript regular expressions with live highlighting, capture groups, and a replace preview. Slow patterns are stopped before they freeze the page.
Open source on GitHubPattern and test string
JavaScript (ECMAScript) syntax. You can also paste a literal like /abc/gi.
Matches
Runs entirely in your browser. Nothing you paste here is uploaded or stored.
Regex syntax. The tokens you’ll use most in JavaScript regular expressions.
| Token | Meaning | Example |
|---|---|---|
| . | Any character except a line break (any character with the s flag) | a.c matches abc, a-c |
| \d \w \s | Digit, word character [A-Za-z0-9_], whitespace | \d{3} matches 404 |
| \D \W \S | The opposite of \d, \w, \s | \S+ matches a run of non-spaces |
| [abc] [^abc] [a-z] | Character class, negated class, range | [^,]+ matches up to a comma |
| ^ $ | Start and end of the input (of each line with the m flag) | ^ERROR matches lines starting with ERROR |
| \b \B | Word boundary, not a word boundary | \bid\b matches id but not user_id |
| * + ? | Zero or more, one or more, zero or one | colou?r matches color and colour |
| {n} {n,} {n,m} | Exactly n, at least n, between n and m | \d{2,4} |
| *? +? ?? | Lazy versions: match as little as possible | <.+?> matches one tag at a time |
| (…) (?:…) | Capturing group, non-capturing group | (\d+)ms captures the number |
| (?<name>…) \k<name> | Named group and a backreference to it | (?<q>["']).*?\k<q> |
| a|b | Alternation: a or b | ERROR|WARN |
| (?=…) (?!…) | Lookahead, negative lookahead | \d+(?=px) matches 12 in 12px |
| (?<=…) (?<!…) | Lookbehind, negative lookbehind | (?<=\$)\d+ matches 5 in $5 |
| \p{L} \p{Emoji} | Unicode property escapes (need the u flag) | \p{L}+ matches café |
Replacement patterns. Special sequences you can use in the replace field.
| Pattern | Inserts |
|---|---|
| $1, $2 … | The text of capture group 1, 2, … |
| $<name> | The text of a named group |
| $& | The whole match |
| $` | The text before the match |
| $' | The text after the match |
| $$ | A literal dollar sign |
More free tools. Free, open source, no sign-up. See all tools · Source on GitHub
Frequently asked questions
How do I test a regular expression?
Type the pattern between the slashes, choose the flags, and paste your test string. Matches are highlighted as you type, and the list on the right shows each match with its position and every capture group. Turn on Replace to preview the result of String.replace with your replacement pattern.
Which regex flavor does this tester use?
It uses your browser’s JavaScript (ECMAScript) engine, the same one your front-end code runs on. Most syntax is shared with PCRE, Python, and Java, but there are differences: JavaScript has no possessive quantifiers, atomic groups, or inline modifiers like (?i), and lookbehind and named groups need a modern browser.
What do the g, i, m, s, u, and y flags do?
g finds all matches instead of the first, i ignores case, m makes ^ and $ match at line breaks, s lets . match line breaks, u enables full Unicode mode including \p{…} property escapes, and y (sticky) only matches at the exact position where the last match ended.
Why does my regex freeze or time out?
Patterns with nested or overlapping quantifiers, such as (a+)+ or (.*,)*, can backtrack exponentially on text that almost matches. This tester runs your pattern in a background worker and stops it after one second so the page stays responsive. Make the pattern more specific, for example [^,]* instead of .*, to fix it.
Is my test string sent anywhere?
No. Matching happens in your browser in a Web Worker. Nothing you type is uploaded or stored, so you can test against real log lines, but avoid pasting secrets anyway.