Skip to content
codevory

Regex Tester

Test JavaScript regular expressions with live highlighting, capture groups, named groups and replacement. A pattern that runs too long is stopped instead of freezing the page.

Regex Tester: the tool

Enter a pattern to test it against your text.

Text

Matches highlighted

How to use Regex Tester

  1. Type a pattern without the surrounding slashes, and toggle the flags you need. g finds all matches instead of the first one.
  2. Paste the text to search. Matches are highlighted as you type, and Match details lists each match with its position and capture groups.
  3. Tick Replace and enter a replacement such as $2-$1 or $<name> to preview the result of replacing every match.
  4. If the pattern is invalid, the message says what is wrong. If it takes more than 2 seconds, it is stopped and you are told why.

Example

A date pattern with three named groups, run with the g flag, and a replacement that rewrites the order of the parts.

Pattern and text
/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g

Released 2026-11-06, patched 2026-11-20.

Replacement: $<day>/$<month>/$<year>
Result
Match 1 at 9-19: 2026-11-06  (year=2026, month=11, day=06)
Match 2 at 29-39: 2026-11-20  (year=2026, month=11, day=20)
Replaced: Released 06/11/2026, patched 20/11/2026.

About this tool

The tester uses your browser's own JavaScript regular expression engine, so it behaves exactly like the RegExp in your code for the same flags. It does not emulate PCRE, Python or Java: features such as possessive quantifiers, atomic groups and recursion are not available in JavaScript, and lookbehind, named groups, Unicode property escapes (\p{L}) and the v flag depend on the browser version.

Regular expressions can hang. A pattern with nested quantifiers such as (a+)+$ tries an exponential number of ways to fail on a text like aaaaaaaaaaaaaaaaaaaaaaaa!. To protect the page, the match runs in a background Web Worker with a 2-second limit. If it does not finish, the worker is stopped and the page stays responsive. This is the same problem that causes denial-of-service bugs (ReDoS) in servers that run user-supplied patterns.

Empty matches are handled correctly: the search steps over them, one character at a time, or one whole character in unicode mode, instead of looping forever. At most 1,000 matches are listed, and matches are highlighted for texts up to 200,000 characters. Neither the pattern nor the text leaves your browser.

Regular expression cheat sheet

SyntaxMeaningExample
. \d \w \sAny character (not line break), digit, word character, whitespace\d+ matches 2026
[abc] [^abc] [a-z]One of the listed characters, none of them, or a range[A-Z][a-z]+
* + ? {n,m}Zero or more, one or more, optional, between n and m times\d{2,4}
*? +?Lazy: as few characters as possible<.+?> matches one tag
^ $ \bStart, end of text (or line with m), word boundary\bcat\b
(abc) (?:abc) (?<n>abc)Capture group, non-capturing group, named group(?<year>\d{4})
a|bAlternation: a or bcat|dog
(?=x) (?!x) (?<=x) (?<!x)Lookahead and lookbehind, positive and negative\d+(?=€)
\1 \k<n>Refer back to a group(\w)\1 matches aa
\p{L} \p{Lu}Unicode letter, uppercase letter (needs u or v)\p{L}+

Frequently asked questions

Which regex flavour does this use?

JavaScript, as implemented by your browser. It is the right tool for code that runs in a browser or in Node.js. Patterns written for PCRE, Python, Java or .NET may use syntax that JavaScript does not support.

What does the 2-second limit mean?

A pattern with catastrophic backtracking can run for minutes or years on a short text. The tester runs it in a background worker and stops it after 2 seconds, so your page does not freeze. The message names the likely cause: nested quantifiers like (a+)+ or overlapping alternatives.

Why do I only get one match?

Without the g flag a regular expression finds only the first match. Turn on g to find them all.

How do replacement templates work?

$1 to $99 insert numbered groups, $<name> inserts a named group, $& inserts the whole match, $` and $' insert the text before and after it, and $$ is a literal dollar sign.

What is the difference between the u and v flags?

Both turn on full Unicode matching, so . matches a whole emoji and \p{...} works. v is newer and adds set operations and string properties inside character classes. They cannot be combined, and v needs a recent browser.

Is my text sent anywhere?

No. The pattern runs in a worker inside your browser, and nothing is uploaded.