Regex Tester

A regex tester lets you try a regular expression against sample text and see every match highlighted. Type a JavaScript pattern and flags below to inspect matches, capture groups and replacements live.

Reviewed by ToolNook editorial team Updated Sources

Flags

Matches highlighted

–

#MatchIndexGroups

What is a regex tester?

Regular expressions (regex) are compact patterns for finding and manipulating text: validating email addresses and phone numbers, extracting dates from logs, cleaning up CSV files or doing powerful search-and-replace in a code editor. They are also famously easy to get subtly wrong. A tester lets you try a pattern against sample text and see the results immediately, before you put it into code.

This tester uses your browser's own JavaScript regex engine, so results match exactly what String.prototype.match, matchAll and replace will do in your code. Matching runs in a background worker, so even a runaway pattern cannot freeze the page; it is stopped after 1.5 seconds with an explanation.

How to use it

  1. Type your pattern between the slashes. Do not include the slashes or flags in the box.
  2. Tick the flags you need, for example g to find all matches and i to ignore case.
  3. Paste sample text into the test string. Matches are highlighted as you type.
  4. Check the table for each match's position and capture groups, and enter a replacement to preview the result of replace().

Quick reference

PatternMeaning
\d \w \sDigit, word character, whitespace (uppercase = the opposite)
.Any character except a newline (any character with the s flag)
* + ? {2,5}0 or more, 1 or more, optional, between 2 and 5 times
^ $ \bStart, end (of each line with m), word boundary
[abc] [^abc]Any of a, b or c; anything except them
(…) (?<name>…) (?:…)Capture group, named group, non-capturing group
(?=…) (?!…)Lookahead: followed by / not followed by

Example

The sample pattern ([A-Z][a-z]+) ([A-Z][a-z]+) with the g flag finds two capitalised words in a row. In the sample text it matches “Ada Lovelace”, “Alan Turing” and “Grace Hopper”, capturing the first name in group 1 and the surname in group 2. The replacement $2, $1 swaps them, so the first line becomes “Lovelace, Ada was born in 1815.”

Change the pattern to \d{4} to find the three years instead, or to (?<year>\d{4}) to see a named group in the match table.

More worked examples

Find dates: the pattern \d{4}-\d{2}-\d{2} with the g flag matches ISO dates such as 2026-10-24 in a log file.

Common mistakes to avoid

  • Forgetting the g flag. Without it, JavaScript stops after the first match.
  • Writing nested quantifiers. Patterns like (a+)+ can hang on long input; the tester stops them after 1.5 seconds.
  • Escaping for the wrong context. In a JavaScript string, backslashes must be doubled. To compare outputs, use the text diff checker.

Sources and methodology

The calculations on this page follow these published standards and references. The code is covered by automated tests against known values.

Frequently asked questions

Which regex flavor does this use?

JavaScript (ECMAScript), as implemented by your browser. Most syntax is shared with PCRE, Python and Java, but some features such as possessive quantifiers are not available.

What is catastrophic backtracking?

Patterns with nested quantifiers, like (a+)+$, can take exponentially long on certain inputs. The tester runs in a separate worker and stops a pattern that takes longer than 1.5 seconds.

How do I reference groups in a replacement?

Use $1, $2 and so on for numbered groups, $<name> for named groups, and $& for the whole match.

Why does my pattern only find one match?

Without the g (global) flag, JavaScript stops after the first match. Tick g to find them all.