Saved

Press the star next to a tool's name to save it.

All my tools

Regex Tester

Type a regular expression and some text, and this regex tester highlights every match as you type, lists each match with its capture groups and previews a find-and-replace.

Restored your last values ·

Flags

Your result opens on the next page. This tester uses JavaScript’s regular expressions, the same as in browsers and Node.js. Other languages are similar but not always identical.

Matches

–

Type a pattern and some text to test it.

Recent results

A regex tester lets you try a regular expression on sample text before you use it in code, a form or a search box. Regular expressions are patterns used to match combinations of characters in text. Type the pattern and your text, and this regex tester highlights every match, shows the capture groups for each one and can preview a replace.

How to use the regex tester

  1. Type the pattern without slashes, such as \d+, or paste a literal such as /colou?r/gi and the flags are set for you.
  2. Choose the flags you need, such as g for every match or i to ignore case.
  3. Paste your test text. Matches are highlighted as you type.
  4. Tick Try a replace to see the text after a replace, using $1 or $<name> for groups.

Regex flags

Flags change how the whole pattern searches. They can be used alone or together, in any order.

FlagWhat it does
gGlobal search: find every match, not just the first.
iCase-insensitive search.
mMultiline: ^ and $ match the start and end of each line, not only of the whole text.
sLets . match new-line characters.
uUnicode: treats the pattern as a sequence of Unicode code points.

Common patterns

PatternMatches
\d+One or more digits
^\s+|\s+$Spaces at the start or end (with the m flag, of each line)
\b\w+\bWhole words
[A-Z]{2,}Two or more capital letters in a row
(\d{4})-(\d{2})-(\d{2})A date such as 2026-12-31, with year, month and day as groups

Capture groups and replacing

Parentheses in a pattern capture part of each match as a group. The table of matches shows each group's value, numbered from $1, or by name for named groups written as (?<year>\d{4}). In a replace, $1 inserts the first group and $<year> a named one, so (\d{4})-(\d{2})-(\d{2}) replaced with $3/$2/$1 turns 2026-12-31 into 31/12/2026.

Which regex flavor is this?

This tester runs your pattern with JavaScript's own regular expression engine, as browsers and Node.js do. Most simple patterns work the same in other languages, such as Python, PHP or Java, but some features differ, so test in your own language before relying on an advanced pattern.

Avoiding slow patterns

Some patterns, such as nested repeats like (a+)+, can take a very long time on text that almost matches. The tester runs your pattern separately from the page and stops it if it takes too long, so the page stays usable. If that happens, simplify the repeats in the pattern.

To tidy JSON while you work, use the JSON formatter and validator, and to change text case, the case converter.

Worked example: the email pattern the regex tester opens with

The tester opens with the pattern [\w.+-]+@[\w-]+\.[a-z]{2,}, the g and i flags ticked, and two lines of sample text that hold two email addresses, a phone number and a date. It reports 2 matches: hello@example.com at position 14 and sales@example.org at position 35. Positions count from 0, so position 14 is the fifteenth character of the text.

Tick Try a replace and type [email] in the Replace with box. The text after replacing reads “Contact us at [email] or [email].” Now untick g. The tester lists only the first address, and only that one is replaced. MDN puts it plainly: a regular expression with the g flag is the only case where replace() replaces more than once.[2]

Worked example: named groups

Type (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) as the pattern with the same sample text. The tester finds 2026-12-31 at position 75, and the match table shows year: 2026, month: 12 and day: 31. With $<day>/$<month>/$<year> as the replacement, the date becomes 31/12/2026.

The m flag changes what ^ means. On the sample text, ^\w+ with only g finds one match, Contact, because ^ marks the start of the whole text. Tick m as well and it finds two, Contact and Call, one at the start of each line.

Special patterns in the Replace with box

The replacement runs through JavaScript’s own replace(), so these patterns work:[2]

TypeInserts
$&The whole match
$1, $2 …A numbered group, counting from 1
$<name>A named group
$`The text before the match
$'The text after the match
$$A dollar sign

If you ask for a group the pattern doesn’t have, such as $2 when there is only one group, MDN says the characters are inserted as they are.[2]

Escaping special characters

Characters such as . * + ? ( ) [ ] { } ^ $ | and \ have a special meaning. To match one of them as itself, put a backslash in front of it, as in a\*b for the text a*b.[1] MDN notes that wrapping the character in a character class, such as [*], often works too.[1] In a JavaScript literal you must also escape a forward slash, because a slash ends the pattern.[1] In this tester you type the pattern without the surrounding slashes, so a plain / is fine in the box. The Copy as /pattern/flags button adds the backslashes for you.

Limits of the regex tester

  • Five flags. There are boxes for g, i, m, s and u. MDN also lists d, v and y,[1] which the tester doesn’t offer.
  • Test text up to 100,000 characters. Longer text shows an error.
  • Up to 1,000 matches are counted, shown as 1000+ beyond that. The table lists the first 50.
  • A pattern that runs longer than 1.5 seconds is stopped, and the tester tells you to look for nested repeats.
  • A pattern that can match nothing, such as a*, shows empty matches. The tester steps one character forward after each, so it never loops.

To look up a token while you test, keep the regex cheat sheet open.

What next

Use this often? Add Regex Tester to your Home screen.

Frequently asked questions

How do I use the regex tester?

Type your pattern, choose the flags and paste some text. Every match is highlighted and listed with its groups.

What does the g flag do?

It makes the search global, so every match is found instead of only the first one.

Which regex flavor does the regex tester use?

JavaScript’s, the same engine browsers and Node.js use. Simple patterns usually work the same in other languages.

Is my text sent anywhere?

No. The pattern runs in your browser, and your text stays on your device.

Why does the regex tester find only one match?

The g flag is probably off. Without it, the tester stops after the first match and a replace changes only that one. Tick g to find and replace every match.

How do I match a dot or a bracket literally?

Put a backslash in front of it, such as \. for a dot or \( for an opening bracket. Wrapping it in a character class, such as [.], also works.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools