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.
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:
[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.
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:
| Token | Matches | Example |
|---|---|---|
\d / \w / \s | A digit / word char / whitespace | \d\d\d → three digits |
. | Any character except newline (unless s flag) | a.c → abc, a c |
[abc] / [^abc] | One of a set / anything but the set | [aeiou] → a vowel |
* / + / ? | 0+ / 1+ / 0 or 1 of the previous | colou?r → color, 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|b | Either 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.
\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.