Skip to content

Regex tester for JavaScript regular expressions

Write a regular expression, paste some text and see every match highlighted as you type, with numbered and named capture groups, their positions and a live replace preview. Arabic text works properly with the u flag and Unicode property escapes. Each test runs in a background worker with a time limit, so a pattern with catastrophic backtracking is stopped instead of freezing your tab.

Quick answer

Type the pattern between the slashes, tick the flags and paste your text: every match lights up, and the groups are listed below with their values. Tick Replace matches to preview a substitution that reuses groups such as $1, then copy the result or download the matches as CSV.

Based on MDN Web Docs: RegExp (JavaScript reference) · Page updated 23 October 2026

Editor: Abuzar, founder of NeedMyToolsHow we check facts

Examples:

Type a pattern to start.

Patterns run in your browser in a background worker, so a slow pattern cannot freeze the page. Your text is never uploaded.

How to use the Regex Tester

  1. Type the regular expression between the slashes, or paste a literal such as /\d+/g and it is split into pattern and flags. Tick the flags you need.
  2. Paste the text to test. Matches are highlighted at once, and each one is listed with its position and the value of every group.
  3. Tick Replace matches to see the text after a substitution. Copy the pattern as a /…/ literal for your code, copy or download the replaced text, or download all matches as CSV.

Which regex flavour this tester uses

Patterns run on your browser’s own JavaScript engine, which follows the ECMAScript standard, so they behave as they will in JavaScript or TypeScript running on the same engine; Node.js uses the same engine as Chrome. Other languages differ in details. Python, PHP and Java support some syntax that JavaScript does not, such as possessive quantifiers like a++, and they write some features differently, so a pattern copied from them may fail here with a syntax error. Named groups are written (?<name>…), lookbehind (?<=…) is supported, and the newer v flag, which adds set operations inside character classes, works in recent browsers. When the pattern has an error, the engine’s own message is shown so you can find the problem.

Arabic text and the u flag

In JavaScript, \w, \b and \d cover only the English letters A to Z, the digits 0 to 9 and the underscore, so \w+ finds no Arabic words at all and \b does not mark Arabic word edges. Turn on the u flag and use Unicode property escapes instead: \p{Script=Arabic}+ matches runs of Arabic letters and \p{L} matches a letter in any script. Arabic-Indic digits Ù  to Ù© and the Eastern digits Û° to Û¹ used for Persian and Urdu are separate characters that \d does not match, so list them in a class, as the Digits example does. Short vowel marks (tashkeel) are separate characters too, so a word typed with a shadda will not match the same word typed without it; strip them first with the Arabic diacritics remover, or allow \p{M}* after each letter. The test text box sets its direction automatically, so Arabic lines read right to left while the pattern stays left to right.

Groups, positions and replace

Parentheses capture a group that is numbered from the left, (?<name>…) captures a named group, and (?:…) groups without capturing. For every match the tester lists the text, its start and end position and the value of each group; a group that did not take part in the match is marked as not matched. Positions count UTF-16 code units, the same as JavaScript string indexes, so an emoji counts as two. In the replacement, $1 and $<name> insert a group, $& inserts the whole match and $$ writes a plain dollar sign. Without the g flag only the first match is found and replaced, exactly as String.replace does. The CSV download lists up to 5,000 matches with all their groups and opens in Excel or Google Sheets.

Catastrophic backtracking and the time limit

JavaScript regular expressions work by backtracking: when part of a pattern fails, the engine goes back and tries the other ways the earlier parts could have matched. With nested quantifiers such as (a+)+$ or overlapping alternatives such as (a|aa)+$, the number of ways can grow exponentially with the length of a text that does not match, so a few dozen characters can keep the engine busy for minutes. OWASP calls the attack that exploits this ReDoS, regular expression denial of service. Here each test runs in a separate background worker; if it has not finished after 2 seconds, the worker is stopped and you see a warning instead of a frozen page. To fix such a pattern, remove the nesting, make alternatives that cannot match the same text, anchor it, or cap repetition with a range such as {1,50}. A pattern that times out here would block a server in the same way, so fix it before it ships.

Limits and privacy

The text can be up to 2 million characters. The first 100,000 characters are highlighted and the first 200 matches are drawn on the page; the count and the CSV include every match up to 5,000. Nothing is uploaded: the pattern, the text and the results stay in your browser. To check how a pattern treats letter case before you run it on real data, the case converter can produce test text in upper, lower and title case, and the text compare tool shows exactly what a replace changed.

Frequently asked questions

Does this regex tester behave like JavaScript in Node.js?

Yes for JavaScript: it runs your pattern on the browser’s JavaScript engine, which follows the same ECMAScript rules as Node.js. Very new flags such as v need a recent browser and a recent Node.js version.

Why does \w not match Arabic letters?

Because in JavaScript \w means only A to Z, a to z, 0 to 9 and the underscore. Turn on the u flag and use \p{Script=Arabic}+ for Arabic words or \p{L}+ for letters in any language.

What does the g flag change?

Without g the engine stops at the first match, and a replace changes only that one. With g it finds every match in the text and replaces them all.

Why was my pattern stopped after 2 seconds?

It needed too many backtracking steps on this text, usually because of a nested quantifier like (a+)+ or alternatives that overlap. Rewrite that part so each character can be matched in only one way.

How do I use a named group in a replacement?

Name the group in the pattern, for example (?<year>\d{4}), and write $<year> in the replacement box. Numbered groups work too: $1 is the first group from the left.