194 tools

Text Tools · · 4 min read

How to Test a Regex Online (With Live Matches and Groups)

Test JavaScript regular expressions live — highlighted matches, capture groups per match and a real-time replace preview, no install needed.

To test a regex online, paste your pattern and test string into the Regex Tester and it highlights every match live, lists each match's capture groups, and previews what a replacement would look like — all as you type, with no run button.

What the Regex Tester does

It runs a JavaScript regular expression against a block of text and shows you three things at once: which parts of the text matched (highlighted inline), a numbered list of each match with its capture groups, and a live preview of a find-and-replace using that pattern. That combination is what makes it useful for debugging a pattern instead of just running it — you see immediately whether it's matching too much, too little, or the wrong parts of the string.

How to test a regex with Toolbench

  1. Open the Regex Tester.
  2. Type your pattern into the Pattern field (the slashes are shown for you — just type what goes between them).
  3. Toggle flags with the five buttons next to the pattern: g (Global), i (Ignore case), m (Multiline), s (Dot matches newline) and u (Unicode).
  4. Paste or type your text into Test string. Matches highlight immediately below it, and the count of matches updates in the "Highlighted · N matches" label.
  5. Check the Matches panel on the right for each match's text and its capture groups (shown as $1=..., $2=...).
  6. Optionally type a replacement into Replace with — it supports $1, $2 group references — and the result appears live underneath.
  7. Click Copy result to copy the replace output, or use the Send to → menu to send it straight into another Toolbench tool.

If your pattern is invalid, the tool shows the JavaScript error message (like "Invalid regular expression") right under the pattern field instead of silently failing.

Example: pulling emails out of text

The Regex Tester's own default demo is a good worked example. With the pattern (\w+)@([\w.]+), flags gi, and this test string:

Contact ana@acme.com or bo@example.org for access.

it finds 2 matches:

# Match Groups
0 ana@acme.com $1=ana $2=acme.com
1 bo@example.org $1=bo $2=example.org

Type $1 at $2 into Replace with — the exact placeholder shown in the field — and the live preview becomes:

Contact ana at acme.com or bo at example.org for access.

That's the classic "de-spam an email address for display" pattern: (\w+) captures the local part before the @, ([\w.]+) captures the domain including its dots, and the replacement rejoins them with the word "at" instead of the symbol.

Flag reference

Flag Name What it does
g Global Finds every match instead of stopping at the first one. Also required for Replace with to replace more than the first occurrence.
i Ignore case Matches letters regardless of case.
m Multiline Makes ^ and $ match the start/end of each line, not just the start/end of the whole string.
s Dot matches newline Lets . match newline characters, which it normally doesn't.
u Unicode Enables full Unicode handling in the pattern, including Unicode property escapes.

Tips and common mistakes

  • Without the g flag, only the first match is shown and replaced. This mirrors how JavaScript regex actually works — a non-global pattern stops at the first hit in both matching and .replace(). Turn on g if you expect every occurrence to highlight.
  • A pattern with no capture groups still gets a "groups" entry — it shows the match's position in the string (like @12) instead of $1=..., since there's nothing captured to label.
  • Leave Replace with empty to just list matches. With no replacement text, the preview panel shows each matched string on its own line, which is a quick way to extract everything a pattern matches.
  • Very long inputs are capped at 500 highlighted matches so the page stays responsive — if you're testing against a huge block of text, narrow the input or tighten the pattern first.
  • The $1, $2 group syntax in Replace with is JavaScript's own replacement syntax — it's not a separate mini-language, so anything valid in a native String.replace() replacement string works here.
  • Find and Replace — a simpler find/replace with its own regex toggle, for when you already know the pattern works and just want to apply it.
  • Filter Lines — keep only the lines that match a pattern or regex, instead of previewing a replacement.
  • Filter Words — same idea, one word at a time.
  • Text Cleaner — strip whitespace, smart quotes and line breaks before you write a pattern against messy text.

Frequently asked questions

Is my pattern or text sent to a server?

No. Matching runs in your browser as you type. If you're signed in, your pattern and text sync privately to your account so they're there next time; if you're signed out, nothing is saved anywhere.

What regex flavor does the Regex Tester use?

It uses JavaScript's native RegExp, the same engine that runs in every browser and in Node.js. Syntax that's specific to other flavors (like PCRE lookbehind quirks or POSIX character classes) isn't guaranteed to behave the same way.

Why does my pattern only match once even though it appears twice in my text?

The g (Global) flag isn't turned on. Without it, JavaScript regex — and this tool — stops after the first match, for both highlighting and replacing.

How do I reference a capture group in the replacement?

Use $1 for the first group, $2 for the second, and so on, in the Replace with field. The Matches panel lists each group's captured value next to its match so you can confirm which number is which before you rely on it.

Can I use this to validate an email address or other format?

You can test whether a pattern matches, but the tool doesn't ship a built-in "email regex" or validate correctness for you — you supply the pattern, and it shows you exactly what that pattern does and doesn't match against your test string.

More guides

All guides →