Online regex tester

Enter a pattern and some test text to see matches, capture groups and the replaced text live. Everything is computed in your browser; nothing is uploaded.

Regular expression

Waiting for input
Write the pattern body without the surrounding slashes — pasting them anyway is also fine.
Match count
0
First position
-
Capture groups
0
Elapsed
0 ms

Match highlighting

Showing at most 500 matches
Matches are highlighted here as you type.

Match details

Replacement result

Press “Run replacement” to see the result here.

Reading a regular expression without guessing

A regular expression is a small program that describes a set of strings. It is worth learning because the alternative — writing parsing code by hand — is almost always longer and more brittle. The trick is to stop reading them left to right as text and start reading them as quantified pieces.

Characters match themselves, so 2026 matches that literal. Character classes match a set: \d is any digit, \w any word character, \s any whitespace, and [a-f0-9] is a custom set. Quantifiers say how many times the preceding piece repeats: * zero or more, + one or more, ? optional, and {2,4} a range.

Groups do two jobs at once. They let you quantify a whole sub-pattern — (ab)+ — and they capture the matched text so you can refer to it later. That is what the capture-group panel shows, and what $1 refers to in a replacement. Adding ?: at the start ((?:ab)+) keeps the grouping but skips the capture.

Flags change the engine’s behaviour, and most surprises come from them. Without g a pattern stops at the first match, so “it only found one” is nearly always a missing g. i ignores case, m makes ^ and $ match at line boundaries, s lets . cross newlines, and y forces matches to be contiguous from the last position.

The performance trap is catastrophic backtracking. Nested quantifiers such as (a+)+ against a long string that almost matches can make the engine explore an exponential number of paths, freezing the tab. If a pattern is slow on large input, simplify nested quantifiers, anchor the pattern, or split the job into two passes.

Everything here runs against JavaScript’s own regular-expression engine in your browser, which means what you test is exactly what your code will do — no server flavour differences, and nothing leaves the page.

Frequently asked questions

Do I need the slashes around the pattern?

No. Write just the body of the pattern — \d{4}-\d{2}-\d{2}, not /\d{4}-\d{2}-\d{2}/. Flags are set with the buttons above rather than appended.

Why does my pattern match fewer items than I expected?

By default a pattern stops at the first match. Turn on the g (global) flag to find every match. Most “it only found one” reports are a missing g.

What do $1 and $& mean in the replacement?

$& inserts the whole match, $1 inserts the first capture group, $2 the second, and so on. Named groups are referenced with $ in modern engines.

Can a regular expression hang the page?

Yes — nested quantifiers such as (a+)+ against a long non-matching string can backtrack for an enormous number of steps. If a pattern feels slow on a large input, simplify the quantifiers or split the work.