Developer

Test a Regular Expression Against Your Text

Type a pattern and your text. Matches are highlighted as you type, each one listed underneath with its capture groups and its position. The flags are checkboxes, and the replace box shows what the substitution would produce before you run it anywhere that matters.

0matches
0capture groups
$1 and $2 are the capture groups. $& is the whole match.

What the flags change

Five checkboxes cover what people reach for most, and each one changes the result rather than the pattern.

Why your pattern matches more than you meant

Quantifiers are greedy by default. <.*> against <b>hi</b> matches the whole string, because .* takes everything it can and then gives characters back only until the pattern can finish. Adding a question mark makes it lazy: <.*?> stops at the first closing bracket and returns two matches instead of one.

The other common surprise is the dot, which does not match a newline unless you tick s. A pattern tested on a single line and then run over a file will quietly return fewer matches, and the fix is usually that flag rather than the pattern.

What the replacement box understands

The replacement is JavaScript's, so $1 through $9 are the capture groups, $& is the whole match, and $<name> works when the group is named with (?<name>...). A literal dollar sign is $$.

Without the g flag only the first match is replaced. That asymmetry catches people out, because the highlight above still shows one match and the result below still looks right on a short example.

Where a regex is the wrong tool

HTML and XML are the standing example. Tags nest to any depth, attributes can hold the characters you are matching on, and comments can contain anything at all, so a pattern that works on the file in front of you fails on the next one. Use a parser. The browser has DOMParser built in.

Email addresses are the second. The pattern in the box above is a demonstration, not a validator: the real grammar in RFC 5322 allows quoted strings, comments and addresses that no simple pattern accepts. Checking for an @ with something on each side and then sending a confirmation message finds more real mistakes than any pattern will.

Patterns that hang the tab

JavaScript uses a backtracking engine, and some patterns make it explore an exploding number of possibilities. (a+)+$ against thirty a's followed by one b takes longer than anyone will wait. Nothing can interrupt it once it starts, which is why this page tests at most 50,000 characters: a bad pattern still finishes on that much text.

The shape to watch for is a quantifier inside another quantifier where both can match the same characters. If a pattern feels slow on a short string, that is usually why, and splitting it into two simpler passes fixes it.

What stays on your machine

The pattern, the text and the replacement are all handled by the browser's own regular expression engine. Nothing is uploaded, which matters more here than on most tools: people test patterns against log extracts, customer records and production data, and those should not be pasted into a page that sends them somewhere.

Frequently asked questions

Why does my pattern only replace the first match?

Because the g flag is off. Without it, the engine stops at the first match, and the replacement stops with it. Tick the g checkbox and every occurrence is replaced. This is the single most common surprise with replacement in JavaScript, and it is easy to miss because the highlight above still shows the one match correctly.

Why does my pattern stop at the end of a line?

The dot does not match a newline unless the s flag is on. A pattern that works on one line and returns nothing on a paragraph is almost always hitting this. Tick s to let the dot cross line breaks. Note that the m flag is a different thing: it changes what ^ and $ mean, and leaves the dot alone.

Can I use named capture groups?

Yes. Write them as (?<name>...) and they appear in the match list under their name as well as their number. In the replacement box they are written $<name>. Named groups make a long pattern readable months later, when the difference between $3 and $4 has stopped being obvious.

Is this the same regex my language uses?

It is JavaScript's engine, so it matches what runs in a browser or in Node. Most of what you write is portable, but lookbehind, named groups and the \\p{...} property escapes differ between languages, and Python, PCRE and Go each have their own extensions. Test in the language you will ship in before relying on an unusual construct.

Does my text get uploaded?

No. The pattern and the text are run through the browser's own regular expression engine on your machine, and nothing is sent anywhere. That matters here because people test patterns against log extracts and customer records, which should not be pasted into a page that transmits them.

Last updated October 4, 2026