Regex Tester

Test JavaScript regex live with all flags (g i m s u y d): highlighted matches, capture and named groups, indices and replace preview. Hang-proof worker.

//g

Uses your browser's JavaScript (ECMAScript) regex engine in a background worker. Syntax such as possessive quantifiers or inline (?i) modifiers from PCRE/Python may not be supported.

What is Regex Tester?

Tests a JavaScript regular expression against your text as you type. Matches are highlighted, a table shows every match with its position, numbered and named capture groups (and group indices with the d flag), and an optional replacement preview shows the result of String.replace. Patterns run in a background worker that is stopped after 1.5 seconds, so catastrophic patterns cannot freeze the page.

How to use Regex Tester

  1. Enter the pattern (without slashes) in Regular expression.
  2. Tick the flags you need: g, i, m, s, u, y, d.
  3. Paste the text to search into Test string – matches update automatically.
  4. Tick Replace matches with… and type a replacement (with $1, $<name>, $& …) to preview the result.

Example

Input
Pattern (?<y>\d{4})-(\d{2}) with flags g, text "a 2024-05 b 1999-12", replacement $2/$<y>
Output
2 match(es) · replaced: a 05/2024 b 12/1999

When to use Regex Tester

Use it to build and debug regexes for JavaScript, TypeScript and Node.js, and for validation rules or search-and-replace. Other engines (PCRE, Python, Java, .NET, POSIX) differ in syntax and features – for example possessive quantifiers, inline modifiers like (?i) and \A/\Z anchors are not available – so test there too when targeting them.

How Regex Tester works

The pattern is compiled with new RegExp(pattern, flags) inside a Web Worker. With g or y the tool loops over exec() and collects up to 1,000 matches (empty matches advance by one code point to avoid infinite loops); without them only the first match is reported, exactly like JavaScript. Each match records its start and end index, capture groups, named groups and, with the d flag, indices for every group. The replacement preview runs text.replace(regex, replacement). If the worker does not answer within 1,500 ms it is terminated and a timeout message is shown.

Common Use Cases

  • Debugging a validation pattern for form input
  • Extracting data with named capture groups
  • Previewing a search-and-replace before running it on files
  • Learning how flags like m, s and u change matching
  • Checking a pattern for catastrophic backtracking

FAQs

Why does my regex only find the first match?

Without the g (global) flag JavaScript stops after the first match. Tick g to list all matches.

What does the d flag do?

It adds indices to each match, giving the start and end position of every capture group. The tool shows them next to each group.

What happens with a catastrophic pattern like (a+)+$?

The worker running it is terminated after 1.5 seconds and you see a timeout message instead of a frozen tab.

Is this compatible with PCRE or Python regex?

Mostly for basic syntax, but not completely. It uses the ECMAScript engine of your browser.

Explore more categories