Skip to content

Regular Expression (RegEx) Tester

Test a regular expression against sample text, with flags, match highlights and capture groups. Uses the JavaScript engine in your browser.

find_replace

Regular Expression (RegEx) Tester

Test and debug JavaScript and PCRE regular expressions with live syntax highlighting, match counters, and captured groups breakdown.

/ /
Match Highlights & Capture Groups 0 Matches

What this tool does

Enter a pattern, set the flags, and paste some text. The tool runs the pattern against the text and highlights each match, lists the matches, and shows the capture groups for each one. It re-runs as you type.

It uses the JavaScript regex engine

The pattern is run with your browser’s RegExp. That is the right engine if you are writing JavaScript, and it is a close match for many other languages, but it is not PCRE, which is what PHP’s preg_* functions use. Some differences you may run into when moving a pattern to PHP or Python:

  • Named groups are written (?<name>...) in JavaScript. PHP accepts that too, but older Python syntax uses (?P<name>...).
  • Lookbehind works in current browsers, but older ones don’t support it.
  • Flags differ. JavaScript has g i m s u y d. PHP uses modifiers after the closing delimiter, and some options have no JavaScript equivalent, like x (extended) or A.
  • Possessive quantifiers and atomic groups are PCRE features that JavaScript doesn’t have.

If you are writing a PHP pattern, test the basics here, then confirm in PHP.

Flags

The default flags are gi. The g flag finds all matches instead of the first, i ignores case, m makes ^ and $ match at each line, and s lets . match line breaks.

Common mistakes

  • Forgetting to escape a dot. . matches any character, so use \. for a literal dot.
  • Greedy matching. .* takes as much as it can. Use .*? to stop at the first match.
  • Patterns that match an empty string and so seem to match everywhere.
  • Catastrophic backtracking, for example (a+)+$ on a long string. If the page freezes, the pattern is the cause.

Is this PCRE?

No. It uses the JavaScript regular expression engine in your browser. Patterns for PHP’s preg functions mostly carry over, but test them in PHP too.

Why does it only show the first match?

Without the g flag a regex stops after the first match. The default flags include g.

Can a bad pattern freeze the page?

Yes. Nested repetition such as (a+)+ can take exponential time on some input. Simplify the pattern.

Is my text uploaded?

No. Matching runs in your browser.

Which flags are switched on by default?

g and i. The g flag finds every match and i ignores case. You can change the flags.