Regex Tester

Write a regular expression and see matches highlighted in your test text as you type. The tester shows each match with its position, numbered and named capture groups, and can preview a replacement. It uses the JavaScript regular expression engine of your browser.

How to use the Regex Tester

  1. Type the pattern without the surrounding slashes, for example (\d+)-(?<word>\w+).
  2. Tick the flags you need. g finds every match, i ignores case, m makes ^ and $ match at each line, s lets the dot match newlines, u turns on Unicode mode and y makes the match sticky.
  3. Paste your sample text. Matches are highlighted and listed with their capture groups.
  4. Optionally add a replacement such as $2:$1 to preview the result of String.replace.

Flags and groups

Parentheses create capture groups numbered from 1 by the position of the opening bracket. (?<name>...) creates a named group that you can read as $<name> in a replacement. (?:...) groups without capturing. A group that did not take part in the match is shown as undefined.

Without the g flag only the first match is returned. With g, the search continues after each match; an empty match moves the position forward by one character so the search always ends.

JavaScript flavor and catastrophic backtracking

This tool runs the JavaScript engine, so lookbehind and named groups work in current browsers, while features from PCRE or Python such as possessive quantifiers, atomic groups and inline flags like (?i) are not supported. A pattern that works here follows the same rules as RegExp in Node.js and browser code.

Patterns with nested quantifiers, such as (a+)+$, can take exponential time on some inputs. To keep the page responsive the pattern is run in a background worker and stopped after 1.5 seconds with a warning.

Frequently asked questions

Which regex flavor does this use?

The JavaScript (ECMAScript) flavor of your browser. If you need PCRE, Python or Java behavior, check the differences in lookbehind, flags and syntax before copying a pattern.

Why does my pattern match only once?

Without the g flag a regular expression returns only the first match. Tick g to find all matches.

Do I write the pattern with slashes?

No. Enter only the pattern text and choose flags with the checkboxes. In code you would write /pattern/flags or new RegExp("pattern", "flags"), where backslashes need doubling inside a string.

What does the timeout message mean?

The pattern took longer than 1.5 seconds on this text, which usually means catastrophic backtracking. Simplify nested repetitions or make the alternatives more specific.

Is my text sent anywhere?

No. The pattern and text are processed in your browser only.