Regex Tester

Type a regular expression and some sample text to see every match highlighted instantly, along with the match count and any capture groups. It uses your browser's native regex engine, so nothing you enter is uploaded.

Enter a pattern and some text to see matches.

How the regex tester works

A regular expression (regex) is a pattern that describes a set of strings. This tool compiles your pattern with the browser's native RegExp engine and runs it against your test text, so the rules it follows are exactly the JavaScript flavor of regex — the same one that runs in every web app.

new RegExp(pattern, flags) match against text highlight

Every match is highlighted in place. With the global flag g, all matches are found; without it, only the first. Capture groups in parentheses ( ) are reported separately so you can see exactly what each group captured.

Worked example

The pattern \b\w+@\w+\.\w+\b with flags gi finds email-like tokens:

\b\w+ matches a word before the @.
@\w+\.\w+ matches the @ host and a dotted suffix.
Result: [email protected] and [email protected] match; plain words don't.

Flags and tips

Flags change how matching behaves: g finds every match, i is case-insensitive, m makes ^ and $ match line starts/ends, s lets . match newlines, and u enables full Unicode. Remember to escape special characters (. * + ? ( ) [ ] { } ^ $ | \) with a backslash when you mean them literally.

Tip: need to clean up text instead of just matching it? Try the case converter or text diff checker.

Quick reference: the tokens you'll use most

You can build the vast majority of practical patterns from a small set of building blocks. These are the JavaScript (ECMAScript) tokens this tester supports:

TokenMatchesExample
\d / \w / \sA digit / word char / whitespace\d\d\d → three digits
.Any character except newline (unless s flag)a.cabc, a c
[abc] / [^abc]One of a set / anything but the set[aeiou] → a vowel
* / + / ?0+ / 1+ / 0 or 1 of the previouscolou?rcolor, colour
{2,4}Between 2 and 4 repeats\d{3,4} → 3–4 digit code
^ / $Start / end of string (or line with m)^Error → lines starting "Error"
(abc) / (?:abc)Capturing / non-capturing group(\d{4})-(\d{2}) → year, month
a|bEither side (alternation)cat|dog

Greedy vs lazy — the bug everyone hits

By default quantifiers are greedy: they grab as much text as possible and then back off only if the rest of the pattern fails. Against the string <b>one</b><b>two</b>, the pattern <b>.*</b> matches the whole line, not the first tag, because .* swallows everything up to the last </b>.

Add a ? after the quantifier to make it lazy — it takes as little as possible. <b>.*?</b> matches each <b>…</b> separately. If your pattern is "matching too much", a missing ? is the first thing to check.

Don't parse HTML or email with one regex. Patterns like \w+@\w+\.\w+ are fine for a quick filter, but real email and HTML have edge cases that defeat any single expression. For HTML use a DOM parser; for email, validate the format loosely then confirm by sending a message. Regex is for finding patterns in text, not for parsing structured languages.

Catastrophic backtracking (ReDoS) — keep it safe

A pattern with nested, overlapping quantifiers — the classic shape is (a+)+$ — can take exponential time on certain inputs because the engine tries an explosion of ways to split the text. On a server this becomes a denial-of-service vector (ReDoS) where one crafted string freezes the process. The fixes: avoid nesting quantifiers over the same characters, prefer specific character classes over .*, and anchor patterns with ^ and $ so the engine doesn't retry from every position. This tester runs in your own browser tab, so a slow pattern only affects you — but the same care matters before you ship a pattern to a backend.

Frequently asked questions

Which regex flavor does this use?

It uses the JavaScript (ECMAScript) regular-expression engine built into your browser. That's the same flavor used in front-end and Node.js code, so patterns behave identically to your app.

What do the flags mean?

g = find all matches, i = ignore case, m = multiline (^ and $ match each line), s = dotall (. matches newlines), u = full Unicode. Combine them with no spaces, e.g. 'gim'.

Why is my pattern invalid?

Usually an unbalanced bracket or parenthesis, or an unescaped special character. The tester shows the browser's error message so you can see exactly what went wrong.

Is my text sent anywhere?

No. The pattern and text are compiled and matched by your browser's own regex engine on your device. Nothing is uploaded, so it's safe for private data.

MB
Mustafa Bilgic · Editor, Calcool
Matching uses the browser's native JavaScript RegExp engine (ECMAScript flavor). Everything runs in your browser — nothing you enter is uploaded, logged or stored.

Related calculators