Regex Tester
Write a pattern, paste some text, and watch matches highlight as you type. Capture groups, named groups and match positions are listed underneath.
How to use the Regex Tester
- Type a pattern in the top box — write it without the surrounding slashes.
- Toggle flags, or type them directly.
gfinds every match,iignores case,mmakes^and$match each line. - Paste your test text. Matches highlight as you type, with capture groups listed below.
Quick reference
| Token | Matches |
|---|---|
. | Any character except a newline (add the s flag to include it) |
\d \w \s | Digit, word character, whitespace. Capitalise to invert. |
* + ? | Zero or more, one or more, optional |
{2,5} | Between two and five times |
[abc] [^abc] | Any one of these, none of these |
(…) (?:…) | Capture group, non-capturing group |
(?<name>…) | Named capture group |
^ $ | Start and end of the string, or of each line with m |
\b | Word boundary |
a|b | Either alternative |
Greedy versus lazy
Quantifiers take as much as they can. Against <b>one</b> <b>two</b>, the pattern <b>.*</b> matches the entire line, because .* runs to the end and then backtracks to the last closing tag.
Adding ? makes a quantifier lazy: <b>.*?</b> stops at the first closing tag and returns two separate matches. This single character is the fix for most "my regex matched too much" problems.
Where regex is the wrong tool
Regular expressions cannot reliably parse nested structures — HTML, JSON, or anything with matching brackets — because nesting requires counting, which regular grammars cannot do. Use a parser instead; for HTML, DOMParser in the browser.
Email validation is the other classic trap. The specification-complete pattern is thousands of characters long and still accepts addresses no mail server would deliver to. Check for an @ with something on either side, then send a confirmation message. That is what real systems do.
Frequently asked questions
Which regex dialect is this?
JavaScript's, using the browser's built-in engine. It is close to PCRE but differs in places: no possessive quantifiers, no recursion, and lookbehind requires a recent browser.
Why does my pattern hang or feel slow?
Nested quantifiers like (a+)+ can cause catastrophic backtracking, where the engine explores exponentially many paths. Rewrite to avoid one repeated group inside another. This tool caps at 10,000 matches as a safety net.
How do I match a literal dot or slash?
Escape it with a backslash: \. matches a full stop, and \/ matches a slash. Inside a character class, most characters lose their special meaning, so [.] also works.
Do I need to escape my pattern differently than in code?
Type it here exactly as it appears between the slashes in a regex literal. If you build patterns from strings in code, remember that string escaping doubles every backslash.
Is my test text private?
Yes. Matching runs in your browser with the native engine, so you can safely test against log lines or customer records.
Related tools
Sort lines alphabetically, numerically, by length or at random.
Strip repeated lines from a list, with case and trim options.
Re-indent JavaScript so nesting and blocks are readable.
Percent-encode text for URLs, query strings and form data.
Count words, characters, sentences and reading time as you type.