Regex Tester — Matches, Named Groups, Replace and a Plain-English Explanation

Enter a regular expression and some test text to see every match and capture group, highlighted in place, try a replacement, and read the pattern explained token by token.

Live demo · real result from this tool

This pattern nests quantifiers, e.g. (a+)+. On long input that nearly matches it can take exponential time (catastrophic backtracking). Make the inner part unambiguous.

Matches2
Capture groups
2
Flags
gi

Matches

#IndexMatchGroup 1 (user)Group 2 (domain)
18asha.rao@example.comasha.raoexample.com
232support@tools.example.orgsupporttools.example.org

Highlighted

After replace

Contact asha.rao at example.com or support at tools.example.org.Not an email: user@localhost

What the pattern means

TokenMeaning
(?<user>Start of capturing group 1, named "user"
[\w.+-]Matches one of: a word character (letter, digit or _), ".", "+", "-"
+…repeated one or more times, as many as possible (greedy)
)End of group
@The character "@"
(?<domain>Start of capturing group 2, named "domain"
[\w-]Matches one of: a word character (letter, digit or _), "-"
+…repeated one or more times, as many as possible (greedy)
(?:Start of a non-capturing group
.The character "."
[\w-]Matches one of: a word character (letter, digit or _), "-"
+…repeated one or more times, as many as possible (greedy)
)End of group
+…repeated one or more times, as many as possible (greedy)
)End of group

15 rows — scroll inside the table, or download the CSV.

Flags

FlagMeaning
gglobal — find every match, not just the first
iignore case

Processed on your device — nothing is uploaded.

How to use the regex tester

  1. Type your regular expression into Pattern, for example (?<user>[\w.+-]+)@(?<domain>[\w-]+(?:\.[\w-]+)+).
  2. Enter any Flags, such as gi.
  3. Paste realistic Test text, including lines that should not match.
  4. Optionally fill in Replace with to preview a replacement.
  5. Read the match count, the match table with every group, the highlighted text, the result after replace and the token-by-token explanation.

What it does and when to use it

Regular expressions are powerful and easy to get subtly wrong. Testing a pattern against real text before it goes into code saves a lot of debugging. This tester shows you not just whether a pattern matches but exactly what each group captured and why.

Use it to:

  • Build a validation pattern for a form field, such as a postcode or an order number.
  • Write the search and replace for a bulk edit in your editor or codebase.
  • Pull values out of log lines, such as dates, IDs or IP addresses.
  • Understand a pattern someone else wrote, with the explanation table.
  • Spot a pattern that could hang on bad input before it reaches production.

If you need a quick reminder of the syntax, the Regex Cheat Sheet lists the common tokens. To see what a replacement changed across a whole file, compare before and after in the Diff Checker. For checking token payloads you have extracted, use the JWT Debugger.

How it works

The tool compiles your pattern with JavaScript’s RegExp and runs it against your text in the browser. It lists each match with its position (index) and every numbered and named group. The highlight view marks matches in the original text. If you enter a replacement, it runs text.replace with your pattern, so $1 and $<name> work exactly as in JavaScript.

The explanation splits the pattern into tokens, such as groups, character classes, quantifiers and anchors, and describes each one in plain English. Invalid patterns and unknown flags are reported with a clear message instead of failing silently.

Worked examples

An optional letter. colou?r with the g flag on “color colour” gives Matches: 2. The explanation describes ? as “repeated optionally (zero or one time)”.

Reformatting dates with named groups. The pattern (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) finds two dates in “Due 2026-10-03, paid 2026-10-15.” and captures year, month and day for each. With the replacement $<day>/$<month>/$<year>, the text becomes Due 03/10/2026, paid 15/10/2026.

A risky pattern. (a+)+$ on “aaaa” matches, but the tool warns about catastrophic backtracking, because a quantifier sits inside another one.

A typo in the flags. Flags gq give Unknown flag q, along with the list of valid JavaScript flags.

Limits and tips

  • Regular expressions cannot reliably parse nested formats such as HTML or JSON. Use a proper parser for those.
  • The pattern runs on your device, so a pathological pattern on very long text can make the page slow.
  • Lookbehind and the v flag need a recent browser. Check support if your code must run on older browsers.

Frequently asked questions

Which regex flavour does this use?
JavaScript's built-in RegExp engine, the same one used in browsers and Node.js. Patterns that work here will work in your JavaScript or TypeScript code. Other languages such as Python, PHP or Java are similar but differ in some details.
What do the flags mean?
g finds every match, i ignores case, m lets ^ and $ match at the start and end of each line, s lets . match line breaks, u turns on full Unicode handling, v is a newer Unicode mode with set operations, y matches only at the current position, and d records the start and end of each group.
How do I use a capture group in the replacement?
Use $1, $2 and so on for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. For example, $<day>/$<month>/$<year> rearranges a date matched with named groups.
What is catastrophic backtracking?
Some patterns, usually ones with a quantifier inside another quantifier like (a+)+, can take an extremely long time on text that almost matches. This can freeze a page or slow a server. The tool warns you when it sees nested quantifiers. Rewrite the pattern so each part can match in only one way.
Can I paste a pattern with slashes, like /abc/gi?
Yes. The tool accepts a regex literal and splits off the flags for you.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close