Regex Tester
Test JavaScript regular expressions live. See matches, capture groups, and apply replacements as you type.
/
/
Enter input above to see the result.
Enter input above to see the result.
What is this for?
Regular expressions are dense and unforgiving. The way to write one that actually works is iteratively — pattern, sample text, see what matches, adjust. This tool gives you that loop in your browser using the JavaScript engine's native RegExp, plus capture-group inspection and a replacement preview. Patterns and inputs never leave the page.
When to use it
- Validating user input (email-shaped, phone-shaped, postcode-shaped) and seeing exactly which inputs pass and fail.
- Parsing log lines, extracting fields, building log filters.
- Designing find-and-replace patterns before running them across a real codebase.
- Debugging a regex you copied from Stack Overflow that doesn't work — paste it here, see what it actually matches.
Common patterns
\b\w+@\w+\.\w+\b— email-ish^\s*$— empty/whitespace-only line (withmflag)(?<year>\d{4})-(?<month>\d{2})— named capture groups(?:.*)— non-capturing group(?=foo)/(?!foo)— lookahead / negative lookahead
Common gotchas
- JavaScript ≠ PCRE. No
\K, no recursive patterns, lookbehind only since ES2018. Patterns from Perl, PHP, or Python often need adjustment. - Without
gflag you get the first match only. Addgfor "find all"; combine withmif anchors should match per-line. - Greedy vs lazy.
.*grabs as much as possible;.*?grabs as little. The difference between matching<b>hi</b> and <i>there</i>as one block vs two. - Anchors at line vs string boundaries.
^and$match string ends by default; withmflag they match each line. - Replacement specials.
$&is the whole match;$1,$2, … are capture groups;$$is a literal$. Forgetting that is a common source of "why is my regex eating my dollars". - Don't parse HTML with regex for anything serious. The classic warning is true: nested tags, comments, and CDATA need a real parser. Regex is fine for one-off log scraping or controlled inputs.
Expert notes
- Regex flavours are not interchangeable. JavaScript's regex engine (which this tool uses) is close to PCRE but not identical. Notable JS-specific differences: no recursive patterns, no
\Kreset operator, no atomic groups before ES2018, and look-behind(?<=…)only landed in 2018. A pattern that "works in PHP" may not transfer to JS without rewriting. Test in the actual target engine before relying on it. - Catastrophic backtracking is the silent regex killer. Patterns like
(a+)+bcan take exponential time on inputs that don't match — the engine tries every combination of how the innera+could subdivide the input. On modern engines (V8 since 2020) most cases short-circuit, but older engines and certain pathological patterns still hang the page. If a regex test takes more than a fraction of a second on short input, you have a problem. - Unicode awareness is opt-in. By default,
\win JavaScript regex matches only ASCII[A-Za-z0-9_]— not "é", not "中", not "العربية". To get Unicode-aware matching, add theuflag, and for full Unicode property classes (matching every letter regardless of script), use\p{L}with theuflag. Email validators and "word" matchers written without these silently fail on non-ASCII text. - Greedy vs lazy is about backtracking direction.
.*greedy consumes everything then backs off;.*?lazy consumes nothing then expands. Same final match on simple inputs; very different performance on complex ones. Default to lazy when you have an explicit terminator (.*?</div>is almost always what you want, not.*</div>). - For production validators, write tests, not regex. Common regex mistakes — over-permissive email validators that accept
foo@bar, IP-address patterns that match999.999.999.999, URL patterns that miss IDN domains — are best caught by a unit-test suite with real-world positive and negative examples. The regex itself is the implementation; the tests are the spec.