Home› Generators & Utilities› Regex Tester

Regex Tester

Type a regular expression and watch every match light up in your test text. Inspect capture groups, preview a replacement, and share the finished pattern with a link. Nothing you paste leaves your browser.

Pattern & test string

/gi
Write the pattern only — no surrounding slashes. Library patterns above replace what is in the box and switch the global flag on.
Use $1 for the first capture group, $& for the whole match, $<name> for a named group, and $$ for a literal dollar sign.
Matches found
—
Enter a pattern to begin
Capture groups
—
First match at
—
Characters matched
—
Lines with a match
—

Highlighted test string

match alternating match zero-length match

After replace

Regex cheat sheet

Character classes

.Any character except a newline (add the s flag to include newlines)
\d \DA digit / anything that is not a digit
\w \WA word character (letter, digit, underscore) / anything else
\s \SWhitespace / anything that is not whitespace
[abc]Any one of a, b or c
[^abc]Any character that is not a, b or c
[a-z0-9]A range — any lowercase letter or digit

Quantifiers

*Zero or more — can match nothing at all
+One or more
?Optional — zero or one
{3} {2,} {2,5}Exactly 3, at least 2, between 2 and 5
+? *?Lazy versions — take as little as possible instead of as much

Anchors and boundaries

^ $Start / end of the string, or of each line with the m flag
\b \BA word boundary / a position that is not a word boundary

Groups, alternation and lookaround

(abc)Capture group — becomes $1 in the replacement and a column in the table below
(?:abc)Group without capturing — use it when you only need the grouping
(?<year>\d{4})Named capture group — reachable as $<year>
a|bAlternation — a or b
(?=abc) (?!abc)Lookahead: what follows must / must not match
(?<=abc) (?<!abc)Lookbehind: what precedes must / must not match
\1Backreference — repeat whatever group 1 captured

Escaping

The characters . * + ? ^ $ { } ( ) | [ ] \ / carry meaning. To match one literally, put a backslash in front of it: \. matches a real dot, \$ matches a dollar sign. Inside square brackets most of them lose their power, so [.+] already means a literal dot or plus.

Regex tester FAQs

Is my text sent to a server?

No. The pattern and the test text never leave your browser. Matching runs on the built-in JavaScript RegExp engine on your own device, so you can safely paste log lines, sample records, or anything else you would not want to upload. The only time anything is transmitted is if you press Copy share link, which deliberately stores the pattern and text so the link can reopen them.

Which regex flavour does this tester use?

ECMAScript — the flavour built into JavaScript and therefore into every browser and Node.js. It supports lookahead, lookbehind, named capture groups, and Unicode property escapes. It does not support recursion, atomic groups, or possessive quantifiers, which exist in PCRE and Perl. Patterns written for Python or PCRE usually transfer unchanged; the main difference is that a named group is written (?<name>…) rather than (?P<name>…).

What do the flags g, i, m, s, u and y do?

g (global) keeps searching after the first match, so you see every hit instead of one. i makes the pattern case-insensitive. m (multiline) makes ^ and $ match at the start and end of each line rather than only the whole string. s (dotAll) lets . match newline characters too. u turns on full Unicode mode, which is required for property escapes such as \p{L}. y (sticky) forces each match to begin exactly where the previous one ended.

How do I use capture groups in the replacement?

Numbered groups are inserted as $1, $2 and so on, the whole match is $&, and a named group is $<name>. Write $$ for a literal dollar sign. The replacement preview uses the browser's own String.replace, so what you see here is exactly what your code will produce.

Why does my pattern find zero-length matches?

Any pattern whose parts are all optional can match nothing at all — a * or ? quantifier, an empty alternation branch, or a lone lookahead all succeed without consuming a character. This tester marks those hits with a thin red bar and steps past them so the search cannot loop forever. If you did not intend them, swap * for +, or anchor the pattern so it has to consume something.

Why is my regex so slow on long text?

Nested quantifiers — a repeating group around something already repeatable, such as (a+)+ — can force the engine to retry an enormous number of paths before giving up. This is catastrophic backtracking, and it happens in every language, not just here. Rewrite the pattern so the alternatives cannot match the same characters, replace a lazy .*? with a negated character class such as [^,]*, and anchor the pattern wherever you can.