Regex Tester
Write a pattern, see what it matches as you type. Groups are listed for every match, and the two traps that catch everyone — empty matches and patterns that hang — are called out.
How to use it
- Type the pattern without the surrounding slashes.
- Tick the flags you need.
gis on because without it you only ever see the first match, which confuses everyone once. - Matches are highlighted above and listed below with whatever each group captured.
The empty match, which is not a bug
A pattern like \d* can match nothing at all, and
nothing is a perfectly good match — there is an empty string
between every pair of characters. So a pattern that can match
nothing matches everywhere, once per position, and the list fills up
with matches you cannot see.
Those are marked in red here rather than hidden, because the same thing in your own code is an infinite loop: a search that finds an empty match at position 5 and then starts again from position 5 will never move. Every regex engine makes you handle this by hand.
The pattern that freezes the tab
Some patterns take longer than the age of the universe on inputs
only thirty characters long. The classic shape is a repeat inside a
repeat — (a+)+b, or (\s*,)*$.
Against text that nearly matches, the engine tries every
possible way of splitting the input before admitting defeat, and the
number of ways doubles with every character.
This page times every run and warns you when a pattern has that shape. It cannot stop one that has already started: JavaScript runs a regular expression to the end with everything else paused, so a bad pattern freezes the whole tab, here and anywhere else. If this page stops responding, that is what happened, and it is worth knowing because the same pattern on a server is a way to take the server down.
The example, and the in it
The pattern above ends with , a word boundary. Take
it off and a third match appears: \.in happily matches
the .in sitting inside .invalid, so an
address that should not match does. It is a small thing that causes
a lot of quiet wrongness — a pattern for cat
finding it inside category, a pattern for a currency
code finding it inside a word.
Flags, in one line each
g find every match instead of stopping at the first.
i treat capitals and small letters as the same.
m make ^ and $ mean the start
and end of each line rather than of the whole text.
s let . match a line break, which it
normally refuses to do. u handle characters outside the
basic set properly, which matters the moment there is an emoji or an
Indian language in the text.
Your text stays here
The pattern and the text are both used by JavaScript in this page. Nothing is uploaded, which is the reason to use a page like this on a real log file rather than a made-up sample.
Frequently asked questions
Do I include the slashes around the pattern?
No. Type just the pattern itself - if you have /\d+/g from somewhere else, type \d+ here and tick the g flag.
Why do I only get one match?
The g flag is off. Without it a regular expression stops at the first match by design. It is on by default here for exactly that reason.
What are the red empty markers?
Matches of zero length. Your pattern is able to match nothing, so it matches nothing at every position. It is legal and it is usually not what you wanted - and in your own code it is the classic cause of a loop that never ends.
The page froze. What happened?
A pattern with a repeat inside a repeat, run against text that nearly matches. JavaScript cannot interrupt a regular expression once it starts, so the tab stops until it finishes. Reload and simplify the pattern - the same pattern would do the same thing to a server.
Does it support lookbehind and named groups?
Yes, both, because the test runs in your own browser and uses its regular expression engine. Named groups are shown by name in the match list.
Is my text sent anywhere?
No. Everything happens in JavaScript inside your own browser. Nothing is uploaded and nothing is saved - close the tab and it is gone.