Skip to content
All tools
English

Regex tester with explanation

Write a pattern, paste some text, and see every match and group as you type, with each part of the pattern explained.

Your data never leaves your device

Without slashes, e.g. \d{3}-\d{4}

Flags

How to use it

  1. Write the pattern

    Without the surrounding slashes. Pick flags such as g (all matches) and i (ignore case).

  2. Paste test text

    Matches are highlighted and listed with their groups and positions.

  3. Try a replacement

    Use $1, $ and $& to build the output, then copy the code snippet.

Which regex flavour this is

This tester uses the regular-expression engine built into your browser, so results are exactly what JavaScript and TypeScript (RegExp, String.match, replace) will do, in browsers and Node.js. Most syntax is shared with PCRE, Python and Java, but some is not: JavaScript has no possessive quantifiers or atomic groups, lookbehind is supported in all current engines, and named groups are written (?<name>…).

Flags

  • g global: find every match, not just the first.
  • i ignore case; m multiline: ^ and $ match at each line.
  • s dotAll: . also matches line breaks.
  • u Unicode: treats emoji as one character and enables \p{…} classes such as \p{Script=Arabic}.
  • y sticky: match only at lastIndex; d adds match indices.

Catastrophic backtracking

Patterns with nested quantifiers, such as (a+)+$ or (\w|\d)*x, can take exponential time on text that almost matches. In production this is a denial-of-service bug (ReDoS). Here your pattern runs in a separate worker thread: if it takes longer than two seconds we stop it and tell you, instead of the tab freezing. Fix it by removing the nesting, making alternatives mutually exclusive, or anchoring the pattern.

Matching Arabic text

\w and \b only understand ASCII letters in JavaScript, so they do not work for Arabic words. Use the u flag with [\p{L}\p{M}]+ for words in any script, or \p{Script=Arabic}+ for Arabic only. Testing data you extracted? Format it first with the JSON formatter.

Frequently asked questions

Why does my pattern work in Python but not here?
Flavours differ. Python allows (?P…) and possessive quantifiers in 3.11+; JavaScript uses (?…) and has neither possessive quantifiers nor inline flags in older engines. The error message tells you which part the browser rejected.
Is there a limit on the text size?
We show the first 1,000 matches. The test text can be as long as your browser handles comfortably; very long text with a slow pattern is stopped after two seconds.
Do I type the slashes?
No. Type the pattern only (\d+, not /\d+/g) and choose flags with the switches. The code snippet adds the slashes for you.