DevToolCase
Sign in Sign in

Test a regular expression

Test a JavaScript regular expression: matches highlighted as you type, capturing groups, replacement, no freeze on catastrophic backtracking.

Share this result

Encrypted in your browser. The key stays in the link, after “#”: only the people you give it to can read it, not even DevToolCase.

The link works for

Sign in for longer links or links without expiry, and to find them in your account.

Flags

Runs entirely in your browser: nothing you type is sent or stored.

Testing a regular expression

Type a regular expression and a text: the matches are highlighted as you type, with the text of each capturing group, and the replacement shows what String.replace would give.

The syntax is that of JavaScript, close to the one of PCRE, Python, Java or .NET for everyday patterns. Each language has its extensions: test a complex expression in the language that will run it.

The essentials

SyntaxMatches
.any character but a line break
\d, \w, \sa digit, a word character (letter, digit, _), a space
[abc], [^abc]one of these characters, or none of them
^, $the start, the end of the text (of each line with m)
*, +, ?0 or more, 1 or more, 0 or 1 time
{2,4}from 2 to 4 times
(…), (?<name>…), (?:…)a group, a named group, a group that captures nothing
a|ba or b
\ba word boundary
(?=…), (?!…)followed by, not followed by

Flags

  • g looks for every match, not only the first one.
  • i ignores case, m makes ^ and $ work at each line, s lets the dot match line breaks.
  • u reads the text as Unicode: an emoji is one character, and \p{L} matches a letter of any alphabet.
  • y only matches at the current position, as a tokenizer does.

In the replacement

  • $1, $2… insert the text of a numbered group, $<name> that of a named group.
  • $& inserts the whole match, $$ a dollar sign.

Catastrophic backtracking

An expression such as (a+)+$, on a long line of “a” ending with another letter, tries an exponential number of ways before failing. On a server, that blocks a process: a denial of service called ReDoS. Here the expression runs apart from the page and is stopped after a moment.

To avoid it, do not nest repetitions over the same characters, and prefer precise classes such as [^,]* to .*.

Add this browser’s favorites to your account?

This browser has 0 favorites that your account does not have:

Either way, this browser keeps its favorites: you find them again after signing out.