View
Flags

More information about the Regex tester

Regex tester

Type a regular expression and a test text, and every match lights up as you type, with each capture group underlined in its own colour. The table lists the matches with their position and groups, named groups included. Switch to Replace to try a replacement, to Split to cut the text at the matches, or to Explain to read what every part of the pattern does. A pattern that backtracks without end is stopped instead of freezing the page, and nothing is uploaded. Type a pattern and a test text: every match is marked as you type, and its capture groups are underlined in their own colour. Matches lists each match with its groups (click a row to select it in the text), Replace tries a replacement with $1, $<name> or $&, Split cuts the text at the matches, and Explain reads the pattern piece by piece. Paste a literal such as /\d+/gi and its flags are set too.

How it works

  1. Type a pattern between the slashes, or pick one of the examples, such as dates, email addresses or repeated words, and type or paste your text below it.
  2. Set the flags: g for all matches, i to ignore case, m for ^ and $ at every line, s for a dot that also matches line breaks, u or v for Unicode.
  3. Read the matches in the table, click a row to select it in the text, or switch to Replace, Split or Explain. Copy the regex as /pattern/flags for your code.

Groups in colour

Every capturing group has its own colour: its brackets in the pattern, the line under its text in each match and its column in the table all share it, so you can see at once which part of the pattern caught which part of the text. A group that took no part in a match shows a dash, and named groups show their name.

The pattern in plain words

Explain splits the pattern into its parts and says what each one means: a digit, one character of a set, a lookahead, a group, the same text as group 1, one or more times and as few as possible. Nested groups are indented, so a long pattern from someone else's code becomes readable.

Safe from runaway patterns

Some patterns, such as (a+)+$, can take longer than the age of the universe on a short text, because the engine tries every way to split it. The tester runs each pattern in a separate worker and stops it after 1.5 seconds with an explanation, so the page never freezes. It uses your browser's JavaScript engine, so the results are the ones your code will get.

Frequently asked questions

Is the regex tester free?

Yes. It is free, needs no account and works in any modern browser.

What is the difference between .* and .*? in regex?

.* is greedy: it takes as much text as it can and then backs off. .*? is lazy: it takes as little as it can. On <b>bold</b>, the pattern <.*> matches the whole string, while <.*?> matches <b> and </b> separately. The plain-language explanation marks each repetition as greedy or lazy.

Which regex flavour does it use?

Your browser's JavaScript (ECMAScript) engine, with the flags g, i, m, s, u, v and y. PCRE, Python, Java and .NET mostly agree with it, but differ in details: JavaScript has no possessive quantifiers or atomic groups, and writes named groups as (?<name>...).

How do I use a group in the replacement?

Write $1 for the first group, $2 for the second, and $<name> for a named group. $& is the whole match, $` the text before it, $' the text after it, and $$ a dollar sign. Without the g flag only the first match is replaced.

Why does my pattern only find one match?

Without the g flag, JavaScript stops after the first match. Turn on g to find them all. With y, each match has to start exactly where the previous one ended.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Go to Editor