Regex tester

Test a JavaScript regular expression: matches, indexes, named groups and a replace preview. Runs on your device.

How it works

  1. Type a pattern and switch on the flags you need
  2. Paste the text to test
  3. Read the matches, groups and the optional replaced text

What the tester does

Type a pattern without the surrounding slashes, choose flags and paste a test text. The page lists every match one per line, then a table with the number, the matched text, its zero-based index and its groups. The index counts UTF-16 units, which is what JavaScript's own match index uses, so an emoji counts as 2. The page opens on a pattern for an address with a named user group, a named host group and an ending of com or org, applied to a sample line: it finds ann@example.com at index 8 and bob@test.org at index 27, and skips carol@site.net because its ending is .net. Statistics show the number of matches and the number of capture groups in the pattern. Line breaks in the text are read as LF.

Flags and groups

g finds all matches; without it only the first match is found and replaced. i ignores case, m makes ^ and $ match at each line, s lets the dot match a line break, and u switches on Unicode mode, which is stricter: a pattern such as \- is valid without u and an error with it. The Groups column shows numbered groups as $1, $2 and so on, then named groups by name. A group that took no part in a match shows (no match). An empty match, such as x* gives, is listed as (empty match). A match that holds a line break is shown with the break written as \n so each stays on one line. At most 500 rows are shown, while the count is the full number.

Replace preview

If Replace with is not empty, a second output shows the text after replacing the matches: $1 is the first group, a dollar sign followed by a group name in angle brackets a named group, $& the whole match, $$ a dollar sign, and \n and \t are a line break and a tab. With g off only the first match changes. If the result would pass 5,000,000 characters, the page says so and builds nothing. Leave the box empty to see only the matches. This is the JavaScript flavour of regular expressions, so features from other languages, such as possessive quantifiers or inline flags, may be errors, and lookbehind depends on your browser.

Limits, and slow patterns

The test text is limited to 100,000 characters. A pattern that cannot compile gives a fixed error that never repeats your pattern. The page also refuses patterns that repeat a group that already repeats or chooses between options, such as (a+)+ or (a|aa)*, because they can take exponential time on some text. It also refuses two or more open-ended repeats in a row that overlap, such as .*.*, .+.*, \s*\s* or (.*)(.*). That check is a simple scan: it refuses some harmless patterns, such as (cat|dog)+, and it does not catch every slow pattern. That is why the pattern is not run on the page itself: it runs in the background, and if it has not finished after 1.5 seconds it is stopped and the page says so. The page stays usable while a pattern runs, and a newer keystroke stops the run in progress. This needs a browser with background workers (Web Workers); without one the tool says so instead of running the pattern.

Frequently asked questions

Which regular expression flavour is this?

JavaScript (ECMAScript), run by your own browser. Syntax from PCRE, Python or .NET that JavaScript lacks, such as possessive quantifiers or inline flags like (?i), can give an error. Named groups are supported, and lookbehind works only in browsers that support it.

Why does my pattern find only one match?

The g flag is off. Without g, JavaScript stops at the first match, and the replace preview changes only that one. Switch g on to list every match, for example both addresses in the sample text.

How do I see named groups?

Give a group a name by writing ?< and the name right after its opening parenthesis, then look at the Groups column: named groups appear after the numbered ones, as year = 2026. In the replace box, a dollar sign followed by the name in angle brackets inserts that group. In the sample, the user and host groups are named, and the page shows user = ann and host = example.

Why was my pattern refused with a message about repeating a group?

Patterns such as (a+)+$ or (a|aa)* can take exponentially long on a text like 30 letters a followed by !, so they are not run. Rewrite them with a single repeat, for example a+ or [ab]+. The check also refuses some safe patterns like (cat|dog)+; a bounded repeat such as (cat|dog){1,5} is accepted.

What happens with a very slow pattern?

It is stopped. Patterns run in the background and are stopped after 1.5 seconds, and then the page shows This pattern took too long and was stopped. The page itself keeps responding. Simplify the pattern or test it on a shorter piece of text.

Is my text sent anywhere?

No. The pattern and the text are processed by your browser in this tab and are not uploaded. The pattern, the flags and the replace text are remembered on this device so they are there next time; the test text is not stored. The page only counts that a result was shown, without your text.