Regex tester

Test a regular expression in your browser: your text is never uploaded, there is no limit on its length, and you see every match with its position and groups. Search and replace works with references such as $1.

Result

How it works

  1. Paste your code

    Paste the code in the left box or open a file. No code to hand? Click Example.

  2. Instant result

    The result appears as you type. If there is an error, you see the line and character.

  3. Copy or download

    Copy the result with one click or save it as a file for your editor or project.

Common building blocks

Pattern Meaning
\d a digit, \d+ one or more digits
\w a letter, digit or _
\s a space, tab or line break
. any character except a line break
[a-z] one character from the range
^ and $ start and end (of the line with the m flag)
\b a word boundary
( … ) a group, available as $1, $2 …
(?<name> … ) a named group: $<name>
?, *, +, {2,4} 0 or 1, 0 or more, 1 or more, 2 to 4 times

Search and replace

In Replace with, $1 refers to the first group, $& to the whole match and $<name> to a named group. The example turns dates like 12-09-2026 into 2026-09-12 with the pattern (\d{2})-(\d{2})-(\d{4}) and the replacement $3-$2-$1. Use \n for a new line.

Flags

The g flag (all matches) is always on. You can also type /pattern/i, as in code; the flags after the slash are used. A pattern that works in JavaScript usually works in Python, PHP and Java too, but not always in exactly the same way.

Test on real data safely

Regexes are most often written for logs, exports and customer data. Because this tester runs in your browser, you can paste real lines without sending them to a third party.

JavaScript flavour

The tester uses the regular expressions of JavaScript. Most syntax is the same as in Python, PHP, Java and .NET, but there are differences: lookbehind and named groups need a recent browser, possessive quantifiers and atomic groups are not available, \A and \Z do not exist (use ^ and $), and in the s flag the dot also matches line breaks. Test the final pattern in the language you will use it in.

Slow or "hanging" patterns

A pattern with nested quantifiers such as (a+)+$ can take exponentially long on text that almost matches. This is called catastrophic backtracking. If the page becomes unresponsive, make the pattern more specific, for example a+$ instead of (a+)+$, or avoid .* between two other open-ended parts.

Building a pattern step by step

Start with a short example of what you want to match and extend it one piece at a time, watching the matches change. For dates, (\d{4})-(\d{2})-(\d{2}) is better than \d+-\d+-\d+, because it also tells you which part is the year. For data in JSON, prefer parsing it with the JSON formatter over a regex.

See also: JSON formatter · URL decode.

Frequently asked questions

Which regex flavour does this use?

JavaScript (ECMAScript). Many patterns also work in Python, PHP and Java, but check features such as lookbehind and possessive quantifiers.

Why does my pattern freeze the page?

It probably backtracks catastrophically. Avoid nested quantifiers like (a+)+ and make the pattern more specific.

How do I refer to a group in the replacement?

Use $1, $2 and so on, $& for the whole match, and $<name> for a named group.

Is my text uploaded?

No. The matching happens in your browser and nothing is sent.