Tools / Regex Tester

Regex Tester

Try a JavaScript regular expression against sample text. Matches are highlighted, capture groups are listed, and you can preview a replacement before you commit the pattern to code.

Runs in your browser JavaScript regex Stops slow patterns
Pattern

Regular expression

g

A pattern that runs too long is stopped automatically, so this page stays responsive.

Input

Test text

Result

Highlighted matches

-
  • Match
Groups

Match details

Matches and capture groups will appear here.
Replace

Replace preview


            
About this tool

Free JavaScript regex tester with groups and a replace preview

Build and check a regular expression against real sample text before it goes anywhere near production. Every match, capture group, and replacement updates as you type, so you can see exactly what a pattern does instead of guessing and shipping it.

Each match is highlighted in place, and every numbered and named capture group is listed with its exact position in the text. Group colours in the highlighted text match the colours in the result list, so it stays obvious which part of a long pattern captured which piece of text.

Type a replacement to preview the rewritten result, using $1 for a numbered group, $<name> for a named group, and $& for the whole match. That makes it quick to plan redirect rules, clean up log files, rename in bulk, or pull structured data out of messy text. Presets for email addresses, URLs, IPv4 addresses, dates, and UUIDs give you a working starting point.

A pattern that would otherwise run away is stopped automatically, so an accidental catastrophic backtrack never locks up the page. Nothing you type is uploaded or stored, which means you can safely test against real log lines, exports, and customer records.

Regex Tester FAQ

What is a regex tester?

A regex tester lets you run a regular expression against sample text and see what it matches before you put the pattern into code. This one highlights every match, lists the capture groups with their positions, and previews a replacement.

Who should use a regex tester?

Developers, data analysts, QA testers, SEO specialists writing redirect and filter rules, and anyone cleaning up log files, exports, or form input. Testing against real sample text is far quicker than deploying a pattern and waiting to see what it breaks.

Which regex flavor does this tester use?

JavaScript regex syntax, the same flavour used in web and Node.js applications. A pattern that works here behaves the same way in your own code, so there are no surprises when you ship it.

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

g finds every match, i ignores letter case, m lets ^ and $ match at the start and end of each line, s lets a dot match line breaks, u turns on full Unicode matching, and y matches only at the current position.

Why did my pattern time out?

Some patterns, such as nested repeats like (a+)+$, can take an extremely long time on certain text. This is called catastrophic backtracking. The tester stops a pattern that runs too long so the page stays usable, which is also a useful warning that the pattern needs rewriting before it reaches production.

How do I use groups in the replacement?

Use $1, $2, and so on for numbered groups, $<name> for a named group, $& for the whole match, and $$ for a dollar sign.

What is the difference between a numbered and a named group?

A plain pair of brackets creates a numbered group you refer to as $1, $2, and so on. Writing a name inside the brackets creates a named group you can refer to by that name instead, which keeps a long pattern readable when groups are added or reordered.

Why does my pattern match nothing?

The usual causes are an unescaped special character, letter case when the i flag is off, a greedy repeat swallowing more than intended, or the y flag anchoring the search to one position. Simplify the pattern until it matches, then add the pieces back one at a time.

Which characters do I need to escape?

Put a backslash before any character that has a special meaning when you want it taken literally, including a full stop, question mark, plus, asterisk, brackets, braces, pipe, caret, and dollar sign. An unescaped full stop matches any character, which is the most common surprise.

How do I match across more than one line?

Turn on the s flag so a full stop can match a line break, which lets a pattern span lines. The m flag is different: it makes the start and end anchors apply to each line rather than the whole text.

Will these patterns work in PHP, Python, or Java?

Mostly, because the common syntax is shared, but each language has its own differences in named groups, lookbehind support, Unicode handling, and how flags are written. Re-test any pattern in its target language before relying on it.

Is my test text uploaded?

No. The pattern and the test text are handled in your browser and are never uploaded.