Modern Niche World MNW

Regex Tester

Type a regular expression and some text to see every match marked, each one listed with its position and groups, and what a replace would produce.

Type the pattern without the slashes around it, in JavaScript syntax.

Flags

Up to 10 million characters. Matching runs in the background and stops after 1.5 seconds.

$1 or $<name> puts in a group, $& the whole match, $$ a dollar sign. Once you’ve typed here, an empty box previews deleting the matches.

Your pattern and text stay on your device: nothing is sent or saved.

Type a pattern and some text to test it.

Check a regular expression before it goes into your code

A regular expression is a compact pattern for finding text: dates in a log, email addresses in a list, a product code in a file name. Patterns are easy to get almost right. This tester shows exactly what yours matches, so you can fix it before it reaches your code.

How to use it

  1. Type the pattern without slashes, and tick the flags you need.
  2. Paste some text. Every match is marked as you type.
  3. Read the list for each match’s position, line and groups.
  4. To test a replacement, type it in the replace box, then copy or download the result.

What the flags do

  • g finds every match; without it, only the first.
  • i ignores case; m makes ^ and $ work on each line; s lets the dot match line breaks.
  • u reads whole Unicode characters and allows classes such as \p{L}; y needs each match to start where the last one ended; d reports where each group starts and ends.

Reading the results

Matches are marked in two alternating colors, so neighbors stay distinct. The list gives each match’s index (counted from 0), its line and column (from 1), and every group, including groups that didn’t take part.

Quick reference

  • . any character except a line break; \d a digit; \w a letter, digit or _; \s a space, tab or line break.
  • [abc] one of a, b or c; [^abc] anything else; [a-z] a range.
  • * zero or more; + one or more; ? optional; {2,5} two to five. Add ? to take as few as possible.
  • ^ and $ the start and end; \b a word boundary.
  • (…) a group; (?<name>…) a named group; (?:…) a group that doesn’t capture; a|b either.
  • (?=…) and (?!…) followed or not followed by; (?<=…) preceded by.

Good practice

  • Anchor when you can. ^ and $ stop a pattern matching inside longer text.
  • Escape symbols such as . ? + ( and $ with a backslash to match them literally.
  • Avoid repeats inside repeats, such as (\w+)*, which can backtrack for ages.

Good to know

Positions count UTF-16 code units, as JavaScript does, so an emoji counts as two. The list shows the first 1,000 matches. The tester doesn’t check other languages’ syntax or rewrite patterns. To clean a list instead, try Remove Duplicate Lines.

Frequently asked questions

Which kind of regular expression does it test?
JavaScript’s, exactly as your browser runs it. Most of the syntax is shared with Python, PHP, Java and others, but some features differ, such as possessive quantifiers, \A and \Z, and some lookbehind rules. Test in the language you’ll use if your pattern relies on them.
Why did it stop and say the pattern takes too long?
Some patterns, such as (a+)+ on a long line that almost matches, make the engine try an enormous number of ways to match. This is called catastrophic backtracking. The tester stops after 1.5 seconds so the page stays usable. Make the repeated part more specific, or avoid repeats inside repeats.
Why does it find only one match?
Without the g (global) flag, JavaScript stops at the first match, and so does this tester. Tick g to find them all. With the sticky flag (y), each match must start exactly where the last one ended.
Is my text sent anywhere?
No. The pattern and the text are tested in your browser, in a background worker on your device. Nothing is uploaded or saved, and closing the page clears it.