What this regex tester does
The tester runs a JavaScript regular expression against sample text and shows every match highlighted in place, with its position and the value of each capture group. Add a replacement string to preview what String.replace would produce. It uses your browser's own regex engine, so the behavior matches the code you will write in JavaScript, TypeScript or Node.js. Matching runs in a background worker, and a pattern that takes too long is stopped instead of freezing the page.
How to test a pattern
- Type the pattern without the surrounding slashes:
\d+, not/\d+/. - Enter flags, such as
gfor all matches orgito ignore case as well. - Paste the text to search. Results update as you type.
- Optionally fill in Replace with to see the text after replacement.
- Read the highlighted preview and the match table, which lists each match, its index and its groups.
Flags in JavaScript
| Flag | Name | Effect |
|---|---|---|
g | global | Find all matches, not just the first |
i | ignore case | a also matches A |
m | multiline | ^ and $ match at every line start and end |
s | dotAll | . also matches line breaks |
u | unicode | Code-point matching and \p{...} property escapes |
v | unicodeSets | Like u, plus set operations in classes; cannot be combined with u |
y | sticky | Match only at the current position |
d | indices | Record start and end positions of groups |
Replacement patterns
In the replacement, $1 to $99 insert numbered groups, $<name> inserts a named group, $& inserts the whole match, $` and $' insert the text before and after the match, and $$ inserts a literal dollar sign.
Worked examples
Reformatting ISO dates
Pattern (\d{4})-(\d{2})-(\d{2}) with flag g on "Due 2026-11-26 and 2027-01-05." finds 2 matches at index 4 and 19. The replacement $3/$2/$1 gives "Due 26/11/2026 and 05/01/2027."
Named groups
Pattern (?<user>[\w.]+)@(?<domain>\w+\.\w+) on "a@b.com, c@d.org" without the g flag returns only the first match, a@b.com, with user=a and domain=b.com. Add g to get c@d.org as well.
First word of each line
^\w+ with gm on two lines, "one two" and "three four", matches "one" and "three". Without m, only "one" matches, because ^ then means the start of the whole text.
Catastrophic backtracking
Some patterns take exponential time when the text almost matches. The classic case is (a+)+$ on a long run of a's followed by a different character: the engine tries every way to split the a's between the inner and outer group before giving up. Each extra character roughly doubles the work: in a test on a desktop PC, 25 a's took about 4 seconds and 28 took about 30 seconds. The tester runs each pattern in a Web Worker and terminates it after 1.5 seconds, then tells you why. To fix such a pattern, remove the nested quantifier (a+$ matches the same text), or make the alternatives mutually exclusive so the engine has only one way to match.
Tips and common mistakes
- Escape special characters. To match a literal dot, write
\.. Unescaped,.matches any character, sob.comalso matches "bxcom". - Greedy versus lazy.
<.+>on "<a><b>" matches the whole string;<.+?>matches "<a>" and "<b>" separately. - Use the u flag for emoji and accents. Without it, an emoji is two code units and
.matches only half of it. - Do not parse HTML or JSON with regex. Use a real parser; regex is for flat patterns.
Limits and privacy
Patterns can be up to 2,000 characters and the test text up to 200,000 characters. The table lists the first 200 matches and counting stops at 100,000. The highlighted preview covers the first 50,000 characters. Everything runs in your browser: the pattern and the text are never sent anywhere.