Regular Expression Tester

Test a regex against sample text, with capture groups and catastrophic backtracking caught.

The text to run the pattern against. Each line is tested separately.

Without delimiters: \d{4}-\d{2}-\d{2}

100 runs left today · sign up for more

About this tool

Runs a regular expression against your sample text and shows every match, with its position and capture groups.

Backtracking is deliberately capped low. A pattern like `^(a|a?)+$` can match the same text in exponentially many ways — the kind of thing that turns a form field into an outage. Here it fails immediately and says why, which is more useful than a result, because the same pattern would behave the same way in production.

Some textbook examples no longer blow up: PCRE rewrites `(a+)+b` internally so it runs instantly. The shape is still worth flagging, so a nested quantifier is reported whether or not this particular input triggered it.

The syntax is PCRE, which is what PHP, Perl and mostly Python use. JavaScript differs in a few places, notably lookbehind and named group syntax.

Common questions

What is catastrophic backtracking?

A pattern with nested quantifiers, like (a+)+b, that can match the same text in exponentially many ways. Against 30 characters it may take longer than the age of the universe. It is a real denial-of-service vector when the pattern touches user input.

Why does my pattern work here but not in JavaScript?

This is PCRE. JavaScript has no possessive quantifiers or atomic groups, its lookbehind support is newer, and named groups use (?<name>) rather than (?P<name>). Most everyday patterns are identical.

Do I need delimiters?

No. Enter the pattern on its own and pick flags from the options. If you paste one with /slashes/ around it they are stripped, and any trailing flags are read.

Why does . not match my newline?

By design — dot excludes newlines unless the s flag is on. Turn on "dot matches newline" if you are matching across lines.