# Regex Tester

> Test a JavaScript regex with live highlights, capture groups, replace and a plain-English reading of the pattern.

- Page: https://codethatmoves.com/tools/dev/regex-tester/
- Site: Code That Moves
- Category: Developer tools
- Free, runs in the browser, nothing is uploaded
- Last checked: 2026-11-03

## What it does

- Highlights every match as you type and lists the position, text and capture groups of each, with group positions under the d flag
- Toggles all eight JavaScript flags, g i m s u v y and d, and refuses the u and v pair together
- Replace with $1, $<name> and $& and copy the result
- Reads the pattern token by token in plain English, including lookarounds and named groups
- Runs the pattern in a background worker and stops it after one second, so catastrophic backtracking cannot freeze the tab
- Warns about patterns that repeat a group that already repeats, the shape behind catastrophic backtracking
- Copies the pattern as a /regex/ literal or a new RegExp() call, escaped correctly

## How to use it

1. Type a pattern, or pick an example such as an email, a URL or an ISO date.
2. Turn flags on and off, and paste your text. Matches are marked as you type.
3. Read the match table and the plain-English reading, try a replacement, then copy the pattern as code or copy a link to share the test.

## What it checks and why

This tester runs the regular expression engine of your own browser, so it follows JavaScript rules exactly: the result is what new RegExp gives in your code. The text you test never leaves the page. Patterns written for Python, PCRE, Java or .NET can differ, for example in lookbehind support, in the syntax for named groups and in what a dot matches, so check the flavour before you copy a pattern between languages.

Matches are found with a loop of exec calls. A pattern that can match nothing, such as a*, advances one character after an empty match (one whole code point with the u or v flag, as matchAll does), so the loop always ends. The tool stops at 1000 matches and at 200 000 characters of text to keep the page responsive. Each match shows its position, its text and each capture group, with the group name when it has one.

The most serious risk in regular expressions is catastrophic backtracking: a pattern such as (a+)+ takes exponentially longer on a long text that almost matches. In a page a bad pattern freezes the tab and on a server it blocks every request. This tester runs the pattern in a Web Worker and stops it after one second, so you see a Stopped message instead of a frozen page. It also flags the common shapes from the pattern alone; that is a warning, not a proof, so test with long input that does not match.

## Specs and sources

- [MDN: Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions)
- [ECMAScript: Regular Expression Patterns](https://tc39.es/ecma262/#sec-patterns)
- [MDN: RegExp flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#flags)
- [OWASP: Regular expression Denial of Service](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS)

## Limits

- It tests JavaScript regular expressions only. PCRE, Python, Java and .NET have different features and edge cases.
- A run that takes more than one second is stopped and reported. A slow but finite pattern on a slow device can be stopped too; shorten the text to measure it.
- The plain-English reading covers common syntax. Unusual constructs are shown as literal characters, so treat it as a guide and not as a parser.
- The match table shows the first 100 matches, and matching stops at 1000. A shared link keeps up to 2000 characters of the test text.

## Questions

### How do I test a regex in JavaScript?

Write the pattern between slashes or in new RegExp, then call test, match, matchAll or exec on a string. This page does the same in your browser and shows every match, so you can adjust the pattern before you put it in code.

### What does the g flag do in a regex?

It makes the pattern find every match in the text, not only the first. Without it, match returns the first result and replace changes only the first one, which is a common reason for a replace that seems to do nothing.

### Why does my regex work here but not in Python or PHP?

Each language has its own regex engine. JavaScript lacks some features, such as atomic groups, and writes named groups as (?<name>...), where Python uses (?P<name>...). Check the syntax of the target language.

### How do I match a literal dot or other special character?

Put a backslash before it: \. matches a dot, \? a question mark, \( a bracket. The characters that need it are . * + ? ^ $ { } ( ) | [ ] \ and, in a /literal/, the slash. Inside a class, [.] also matches a plain dot.

### What is catastrophic backtracking in a regex?

A pattern like (a+)+ can try an exponential number of ways to split a long text that almost matches, and the engine does not give up. One bad pattern can freeze a browser tab or stall a server. Avoid nested quantifiers and test with long input.
