Regex Tester

Write a regular expression, paste some text and instantly see every match, its capture groups and the result of a find-and-replace.

Matches highlighted
Contact us at hello@ztool.info or support@example.com. Orders: #1042 on 2026-10-28, #1043 on 2026-11-02. Invalid: user@ and @example.com

Match details

—

Replace

🔒 Runs entirely in your browser. Nothing you enter is sent to a server.

Regular expressions are compact and powerful, and also notoriously easy to get slightly wrong. This tester shows exactly what your pattern matches as you type: every match highlighted in the text, a breakdown of capture groups, and a live preview of a find-and-replace.

How to use the regex tester

  1. Type a pattern between the slashes. There’s no need to escape the slashes themselves.
  2. Turn flags on or off with the buttons, or type them in the small box.
  3. Paste your test string. Matches are highlighted in alternating colors so neighbouring matches are easy to tell apart.
  4. Check Match details for each match’s position and capture groups.
  5. Enter a replacement to preview the result of a replace.

Invalid patterns show the browser’s error message straight away.

How matching works

The tester creates new RegExp(pattern, flags) and runs it against your text:

  • With the g flag it uses matchAll to list every match, up to 1,000.
  • Without g it reports only the first match, just as String.match does in code.
  • The replacement uses String.replace, so $1, $<name> and $& behave exactly as they will in your JavaScript.

Patterns run in a Web Worker with a one-second time limit, which protects you from patterns that backtrack catastrophically.

Worked example

The default pattern finds email addresses:

([\w.+-]+)@([\w-]+(?:\.[\w-]+)+)
  • ([\w.+-]+) captures the user name: letters, digits, underscores, dots, plus and minus signs.
  • @ matches the at sign.
  • ([\w-]+(?:\.[\w-]+)+) captures the domain: one or more labels joined by dots. The (?:…) group is non-capturing.

Against the sample text it finds 2 matches:

Match Index Group 1 Group 2
hello@ztool.info 14 hello ztool.info
support@example.com 34 support example.com

user@ and @example.com are correctly ignored. The full stop after example.com isn’t included either, because each domain label must follow a dot and contain at least one character. With the replacement [$1 at $2], the first line becomes Contact us at [hello at ztool.info] or [support at example.com].

Now try (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}) with the replacement $<d>/$<m>/$<y>. It turns 2026-10-28 into 28/10/2026.

Quick reference

Pattern Matches
. Any character except a line break
\d \w \s Digit, word character, whitespace
[abc] [^abc] One of a, b, c, or anything except them
* + ? 0 or more, 1 or more, 0 or 1
{2,4} Between 2 and 4 times
*? +? Lazy: as few as possible
^ $ Start and end of the text (or line with m)
\b Word boundary
(…) (?<name>…) (?:…) Capturing, named and non-capturing groups
(?=…) (?!…) Lookahead, negative lookahead
(?<=…) (?<!…) Lookbehind, negative lookbehind

Tips and pitfalls

  • Escape special characters. To match a literal dot, plus sign or bracket, put a backslash before it: \., \+, \[.
  • Greedy versus lazy. <.+> on <b>bold</b> matches the whole string. <.+?> matches each tag separately.
  • Anchor your validation patterns. ^\d{5}$ checks that the whole input is five digits. Without anchors, \d{5} also matches inside longer numbers.
  • Avoid nested repetition. Patterns like (\w+)* can be very slow. Simplify them, or make the inner part unambiguous.
  • Don’t parse HTML or email exhaustively with regex. Regexes are great for quick checks, but full HTML parsing and perfect email validation need proper parsers.

Frequently asked questions

Which regex flavor does this tester use?

JavaScript (ECMAScript), the engine built into your browser. It supports lookahead, lookbehind, named groups, Unicode property escapes with the u flag and the s (dotAll) flag. Most patterns also work in Python, Java and PCRE, but details such as named group syntax can differ.

What do the flags mean?

g finds all matches instead of just the first. i ignores letter case. m makes ^ and $ match at the start and end of each line. s lets the dot match line breaks. u enables full Unicode matching, including escapes such as \p{L} for any letter.

Why does my pattern only find one match?

Without the g (global) flag, a JavaScript regex stops after the first match. Turn on g to see every match and to replace them all.

Why was my pattern stopped?

Some patterns, such as (a+)+b, can take exponentially long on text that almost matches. This is called catastrophic backtracking. The tester runs patterns in a background worker and stops any that take longer than a second, so your browser never freezes.

How do I use capture groups in the replacement?

Use $1, $2 and so on for numbered groups, $<name> for named groups, and $& for the whole match. To insert a literal dollar sign, write $$.

Last updated October 28, 2026 · By the ZTool team