Regex Tester

Test a JavaScript regular expression against your text and see every match with its index, numbered and named capture groups, and a preview of a replacement.

Use the tool

Why this tool exists

A regex that looks right often matches too much, too little or something unexpected, and the quickest way to fix it is to test against real sample text. Writing a throwaway script, or running it live on production data, is a poor way to do it.

This tester runs your pattern with the JavaScript engine in your browser, so the behaviour matches what your front-end or Node code will do. It lists up to a thousand matches with start and end positions, shows each capture and named group, and previews a replacement that uses numbered or named groups. Your text stays in the page and is never uploaded.

How to use it

  1. Enter the pattern, without surrounding slashes, in the Pattern option.
  2. Set the flags, such as g for all matches, i for ignore case, m or s.
  3. Paste your sample text into the Test text box.
  4. Optionally add a replacement such as $3/$2/$1, then read the match list and the replace result.

Frequently asked questions

Which regex flavour does it use?

JavaScript (ECMAScript), including named groups, lookbehind and Unicode property escapes. Patterns written for PCRE, Python or Java may differ, for example in how they handle possessive quantifiers or inline flags.

Why do I only get one match?

Without the g flag a regex returns only the first match. Add g to the flags field to find all of them. The result line tells you when only the first match was reported.

Can a pattern freeze the page?

Yes. The test runs synchronously, and a pattern with catastrophic backtracking, such as nested quantifiers on long text, can hang the tab. Simplify the pattern or shorten the text, and reload if the page stops responding.

How do I use groups in the replacement?

Write $1, $2 for numbered groups, a dollar sign plus the group name in angle brackets for named groups, $& for the whole match and $$ for a literal dollar sign. The preview shows what String.replace returns.