Skip to content
SPCXTools

Regex Tester

Write a regular expression and see every match, capture group and replacement live.

Runs locally — files never leave your device

Loading tool…

How to use Regex Tester

  1. 1Type your regular expression in the Pattern box — no slashes needed.
  2. 2Choose flags such as g (find all matches), i (ignore case) or m (multiline).
  3. 3Paste the text to search into Test string. Matches are highlighted instantly and counted.
  4. 4Check the table for each match's position and capture groups.
  5. 5Tick Replace and enter a replacement such as $2: $1 to preview the result of String.replace.

Test regular expressions with live results

Regular expressions are powerful but famously hard to read. This regex tester shows you exactly what your pattern does while you type: every match is highlighted in the text, counted, and listed with its position and capture groups. A replace preview shows the result of a search-and-replace before you run it in your code. Everything runs locally in your browser, inside a background worker that protects the page from runaway patterns.

Features

  • Live highlighting of all matches in the test string.
  • Flag toggles for g, i, m, s and u, with the full /pattern/flags literal shown.
  • Match table with index, numbered capture groups and named groups.
  • Replace preview supporting $1, $<name>, $& and other replacement patterns.
  • Clear error messages for invalid syntax, and a one-second safety timeout for catastrophic backtracking.

Practical uses

Validating input. Build and test patterns for postcodes, product codes or usernames against a list of valid and invalid samples before adding them to a form.

Extracting data. Pull email addresses, URLs, dates or IDs out of logs and documents. Capture groups let you split each match into parts, such as user and domain.

Search and replace. Reformat dates from MM/DD/YYYY to YYYY-MM-DD, rename variables, or clean up exported data. Preview the replacement here, then use the same pattern in your editor or script.

Learning regex. Experiment with quantifiers, character classes and anchors and see the effect instantly.

Quick reference

Syntax Meaning
. Any character except a line break (any character with s)
\d \w \s Digit, word character, whitespace
[abc] [^abc] One of / none of the listed characters
* + ? 0 or more, 1 or more, 0 or 1
{2,5} Between 2 and 5 times
^ $ Start and end of text (of each line with m)
(…) (?<name>…) Capture group, named group
(?:…) Group without capturing
(?=…) (?!…) Lookahead, negative lookahead
\b Word boundary

Quantifiers are greedy by default; add ? (as in .*?) to make them lazy. To clean up lists afterwards, try Remove Duplicate Lines, or compare before and after with the Diff Checker.

Frequently asked questions

Which regex flavour does this tester use?
It uses your browser's JavaScript (ECMAScript) regular expression engine — the same one used by Node.js, Deno and front-end code. Most syntax is shared with PCRE, Python and Java, but some features differ, such as possessive quantifiers (not supported) and lookbehind (supported in modern browsers).
Why does my regex only find one match?
Without the g (global) flag, JavaScript stops at the first match. Turn on g to find every match in the text.
How do I reference capture groups in the replacement?
Use $1, $2 and so on for numbered groups, $<name> for named groups like (?<year>\d{4}), $& for the whole match, and $$ for a literal dollar sign.
What happens if my regex is extremely slow?
Some patterns, such as (a+)+$, can take exponential time on certain inputs ("catastrophic backtracking"). The tester runs your expression in a background worker and stops it after one second, so the page never freezes. Rewrite the pattern to avoid nested quantifiers.
What do the s and u flags do?
s (dotAll) lets . match line breaks as well. u (unicode) treats the pattern and text as Unicode code points, which is needed for emoji and for \p{…} property escapes such as \p{L} (any letter).
Is my text uploaded?
No. Matching and replacing run locally in your browser.