Regex Tester
Test JavaScript regular expressions against your text with live match highlighting, capture groups and replacement preview.
How to use this tool
Steps for using the Regex Tester.
- Type your pattern into the Regular expression field without the surrounding slashes — or paste a full literal such as
/\d+/giinto the empty field and it is split into pattern and flags automatically. - Toggle the flags you need:
g(all matches),i(ignore case),m(multiline anchors),s(dot matches newlines),u/v(Unicode),y(sticky) andd(indices). - Paste the text to search into Test string. Matches are highlighted as you type, and the Match details table lists each match with its position and capture groups.
- Turn on Replace mode and enter a replacement such as
$2-$1or$<name>to preview the result ofString.prototype.replace, then Copy it. - If the pattern is invalid, the error banner shows the JavaScript engine's message. Use the Quick reference panel to look up syntax.
Example
Capture the parts of ISO dates
(\d{4})-(\d{2})-(\d{2})1. 2024-03-15 (position 9–19) $1: 2024 $2: 03 $3: 15
2. 2024-04-02 (position 29–39) $1: 2024 $2: 04 $3: 02Common use cases
- Building and debugging form validation patterns for emails, phone numbers or postcodes before adding them to code.
- Extracting IDs, dates or URLs from log lines and checking exactly what each capture group returns.
- Previewing a search-and-replace with back-references before running it across a codebase.
- Checking whether a pattern behaves the same with and without the
m,soruflags. - Spotting patterns that are vulnerable to catastrophic backtracking (ReDoS) before they reach production.
How the regex tester works
Patterns are compiled with your browser's own RegExp constructor, so the results are exactly what str.match(), str.replace() or regex.exec() will give you in JavaScript — including engine-specific features such as lookbehind, named groups, the d indices flag and, where supported, the v (Unicode sets) flag. Flags your browser does not support are shown disabled. Other regex dialects (PCRE, Python's re, Go's RE2, POSIX) differ in syntax and behaviour, so test those patterns in their own runtime.
Matching follows JavaScript semantics closely: without g or y only the first match is reported, the same as exec() on a non-global regex. With g, the tester calls exec() in a loop and, when a match is empty (for example x* or ^ with m), advances one position — or one full code point with u/v — so the loop always terminates. Results are capped at 1,000 matches to keep the page responsive; the status line tells you when the cap is reached.
Some patterns, typically nested quantifiers such as (a+)+$ or overlapping alternations, can take exponential time on inputs that almost match — known as catastrophic backtracking. JavaScript cannot interrupt a running regex, so matching runs in a background Web Worker and is stopped after 2 seconds with a clear message instead of freezing the tab. If you see that message, make the repeated part more specific, avoid nested +/*, or anchor the pattern.
The replace preview uses String.prototype.replace, so replacement tokens behave as in your code: $1–$99 insert numbered groups, $<name> inserts a named group, $& inserts the whole match, ` $ ` and $' insert the text before and after the match, and $$ produces a literal dollar sign. Remember to add the g` flag if you want every occurrence replaced, not just the first.
Limitations
- Uses the JavaScript regex engine only; PCRE-specific syntax such as possessive quantifiers, atomic groups or
(?i)inline modifiers may be rejected or behave differently. - Matching stops after 2 seconds and at 1,000 matches; test strings are limited to 500,000 characters.
- In the rare browser without Web Worker support, matching runs on the page itself with a 50,000-character limit and cannot be interrupted.
Frequently asked questions
Which regex flavour does this tester use?
JavaScript (ECMAScript), via your browser's built-in RegExp. A pattern that works here works the same way in Node.js and browser code running on a similar engine version.
Why does it only find one match?
Without the g (global) flag, JavaScript stops after the first match. Enable g to find every match — this also makes the replace preview replace all occurrences.
Can I paste a regex literal like /abc/gi?
Yes. Paste it into the empty pattern field and the tester splits it into the pattern abc and the flags g and i. Typing slashes inside a non-empty pattern keeps them as literal characters.
What does “Matching stopped after 2 seconds” mean?
The pattern backtracked for too long on your text, usually because of nested or overlapping quantifiers. The same pattern could hang a server that runs it on untrusted input, so it is worth rewriting.
Is my test data uploaded anywhere?
No. Patterns and text stay in your browser; matching runs locally in a Web Worker. Nothing you type is sent to a server or to analytics.