Regex tester

Write a regular expression and see every match highlighted as you type, with capture groups, replacements, a plain-English explanation of each part, and ready-to-paste code. Mistakes are marked right in the pattern.

Flags
Test text
Type a pattern

What the tester catches

A regex that silently does the wrong thing is worse than one that throws an error. As well as syntax errors, the tester marks patterns that are valid but probably not what you meant:

  • Pasted literals and strings: /\d+/gi or r"\d+" pasted with the slashes, quotes or flags, which aren’t part of the pattern. Pasting a literal splits out the flags for you.
  • Other flavours’ syntax: Python’s (?P<name>), PCRE’s \A, \Z, atomic groups, inline flags like (?i), and possessive quantifiers.
  • Character class traps: [A-z] (which also matches [ \ ] ^ _ and a backtick), [cat|dog] (single characters, not words), \b inside a class (a backspace), and ranges that run backwards.
  • Escapes that need the u flag, like \p{L} or \u{1F600}, which silently match something else without it.
  • Backreferences to missing groups, which JavaScript reads as octal escapes.
  • Empty alternatives like (a|) that let a group match nothing.

When a fix is certain, it’s one click away (and one undo away).

Hints when nothing matches

If your pattern finds nothing, the tester tries likely variations and tells you if one would work: “this would match with the i flag”, or “with m, ^ would match at each line”. If every match is empty, it says so, because a* matching nothing everywhere is a common surprise.

Replace, explain and code

  • Replace shows the result of text.replace(). References like $1, $<name> and $& are checked against your groups, so a typo doesn’t quietly produce literal $3.
  • Explain breaks the pattern into its parts and says what each one does, indented by group.
  • Code gives the pattern for JavaScript, Python, PHP and Go, with escaping and flag differences handled and noted.

Quick reference

TokenMatches
\d \w \sDigit, word character, whitespace (capitals for “not”)
. Any character except line breaks (add s for all)
[abc] [^abc]One of, or none of, these characters
* + ? {2,5}0 or more, 1 or more, optional, 2 to 5 times
*? +?Lazy: as few as possible
(…) (?:…) (?<name>…)Capture, group without capturing, named capture
(?=…) (?!…) (?<=…) (?<!…)Lookahead and lookbehind
^ $ \bStart, end, word boundary

Comparing two outputs? Use the text diff checker. Need the regex to validate JSON first? Run it through the JSON formatter.

Questions people ask

Which regex flavour does this use?
JavaScript (ECMAScript), run by your browser’s own engine, so what matches here matches in Node, Deno and the browser. Patterns copied from Python, PCRE or Java are checked for syntax JavaScript doesn’t support, like (?P<name>…), \A or possessive quantifiers, and the JavaScript version is suggested.
Why does my regex only find the first match?
Without the g flag, JavaScript stops after the first match. Turn on g to find them all. The tester points this out when there would be more matches.
Why does ^ or $ only match once?
By default, ^ and $ match the start and end of the whole text. Turn on the m (multiline) flag to make them match at the start and end of every line.
Why does . not match a new line?
Because . excludes line breaks unless you turn on the s (dotAll) flag. Alternatively, use [\s\S], which matches anything.
My regex froze the page. What happened?
Catastrophic backtracking. Nested quantifiers like (a+)+ or overlapping alternatives can take exponential time on text that almost matches. The tester runs your pattern in a background worker with a time limit, so it stops it, shows which part is to blame and how to rewrite it.
Is my test text sent anywhere?
No. Everything runs in your browser. You can safely paste logs or data you wouldn’t want to share.
↑↓ move↵ openesc close