Regex Tester

The tester runs your pattern in the JavaScript RegExp engine of your browser, so results match what your own JavaScript code would see. Type the pattern without slashes, such as \d{3}-\d{4}, and use the g flag to find every match.

Highlighted matches

Did this solve your problem?
Prefer us on Google

How to use

  1. Type your pattern without the surrounding slashes, for example \d{3}-\d{4}.
  2. Turn flags on or off. The g flag finds every match; without it only the first match is shown.
  3. Paste the text to search. Matches are highlighted as you type, and the table lists each match with its capture groups.

How it works

The pattern is compiled with the JavaScript RegExp engine built into your browser, so the syntax and behavior are exactly what your own JavaScript code would see. Other dialects such as PCRE, Python or .NET differ in places, for example in lookbehind support in older engines and in possessive quantifiers, which JavaScript does not have.

With the g flag the tester calls exec repeatedly and collects up to 1,000 matches. When a match is empty, such as with a* or a lookahead, the search position moves forward by one character so the loop always ends.

Matching runs in a background worker. If a pattern takes longer than 1.5 seconds, for example because of catastrophic backtracking like (a+)+$, the worker is stopped and you see a timeout message instead of a frozen page.

Regex cheat sheet

TokenMeaning
.Any character except a line break (any character with the s flag)
\d \w \sDigit, word character (letter, digit, underscore), whitespace
\D \W \SThe opposite of \d, \w and \s
[abc] [^abc] [a-z]One of a, b or c; anything but a, b or c; a range
^ $Start and end of the text (of each line with the m flag)
\bWord boundary
* + ?Zero or more, one or more, zero or one
{3} {2,5} {2,}Exactly 3, between 2 and 5, 2 or more
*? +?Lazy versions that match as little as possible
(abc) (?:abc)Capturing group, non-capturing group
(?<name>abc)Named capturing group
a|ba or b
(?=x) (?!x)Followed by x, not followed by x
(?<=x) (?<!x)Preceded by x, not preceded by x
\1 \k<name>Back reference to group 1 or a named group

Flags

FlagEffect
gGlobal: find all matches instead of the first
iIgnore case
mMultiline: ^ and $ match at line breaks
sDot all: . also matches line breaks
uUnicode: treat surrogate pairs as one character and enable \p{...}
ySticky: each match must start exactly where the last one ended

FAQ

Which regex flavor does this use?

JavaScript, as implemented by your browser. Patterns that work here will work the same way with new RegExp in your own JavaScript or TypeScript code.

Why do I only see one match?

Without the g (global) flag, a JavaScript regex stops at the first match. Turn on g to find all of them.

Why did my pattern time out?

Nested quantifiers such as (a+)+ or (.*)* can make the engine try an exponential number of paths on text that almost matches. Make the inner part more specific or remove the nesting.

Is my text sent anywhere?

No. The pattern and text are processed entirely in your browser and never sent to a server.