How to use the regex tester

  1. Type a regular expression, without the surrounding slashes, and choose its flags.
  2. Paste your test text. Matches are highlighted as you type, and Match details lists every match with its position and capture groups.
  3. To preview a search and replace, enter a replacement. Use $1 for a numbered group, $<name> for a named group and $& for the whole match.

Flags

  • g finds every match. Without it, only the first match is found, as with RegExp.exec.
  • i ignores case. m makes ^ and $ match at the start and end of each line.
  • s lets . match line breaks too.
  • u enables full Unicode: characters outside the Basic Multilingual Plane, such as emoji, count as one character, and \p{L}-style property classes work.
  • y (sticky) only matches at the current position, without searching ahead.

JavaScript and .NET regular expressions

The tester uses your browser's JavaScript engine. Most syntax is shared with .NET's System.Text.RegularExpressions: character classes, quantifiers, lazy quantifiers, lookahead and lookbehind, backreferences and named groups ((?<name>...)). The main differences:

  • .NET supports features JavaScript doesn't, such as balancing groups, atomic groups (?>...), right-to-left matching and RegexOptions.IgnorePatternWhitespace.
  • In .NET, \d and \w match digits and letters in every script; in JavaScript they match ASCII only. Use RegexOptions.ECMAScript in .NET for JavaScript-like behaviour.
  • .NET replacement strings use ${name} for named groups; JavaScript uses $<name>.
var regex = new Regex(@"(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})",
    RegexOptions.None, TimeSpan.FromSeconds(1));   // always set a timeout for untrusted input
string result = regex.Replace(text, "${day}/${month}/${year}");

Frequently asked questions

Is my text uploaded?

No. Matching runs entirely in your browser, in a background worker; your pattern and text are never sent to our servers or logged.

Why was my pattern stopped?

A pattern that runs for more than two seconds is stopped. This usually means catastrophic backtracking: nested quantifiers such as (a+)+ or (.*,)* can try an exponential number of ways to match before failing. Make the pattern more specific, for example by replacing .* with a negated class such as [^,]*. The same pattern could hang a server, which is why .NET code should pass a timeout to Regex.

Why are positions different from my editor's?

Positions count UTF-16 code units, as JavaScript does, so an emoji counts as two. Lines and columns start at 1.