Regex Tester (JavaScript)
Test a regular expression on your text: every match with its position and capture groups in a table, plus a find-and-replace preview. JavaScript flavour.
Type a pattern and some sample text to see exactly what a regular expression matches — every match with its position and capture groups, after pressing Calculate. The tester runs your browser's own JavaScript RegExp engine, using the same RegExp API available to JavaScript programs, and previews a find-and-replace with $1-style references before you put the pattern into code.
How to use this tool
- Enter the pattern without slashes, or paste a literal such as
/\d+/gi. - Tick the flags you need: g, i, m, s or u.
- Paste the text to search.
- Optionally enter a replacement to preview the result of
text.replace(). - Press Calculate. Read the match count, then the table of matches and their groups.
Formula
repeat: match = re.exec(text) from re.lastIndex, while the g flag is set
Without g only the first match is returned. Positions count UTF-16 code units from 0, as match.index does in JavaScript. After an empty match the search moves on by one position (one code point with u or v), so patterns like x* cannot loop forever. Patterns run in a separate worker with a two-second limit; a slow expression is stopped without blocking the page.
Example
The default pattern (\d{4})-(\d{2})-(\d{2}) finds 2 matches in the sample sentence: 2026-03-15 at index 15 and 2026-10-01 at index 30, each with 3 groups (year, month, day). 2026/12/01 is skipped because it uses slashes. The replacement $2/$3/$1 turns the sentence into "Invoices dated 03/15/2026 and 10/01/2026 are due…".
Frequently asked questions
Will my regex behave the same in Python, PHP or Java?
The basics — character classes, quantifiers, groups and anchors — are shared, but flavours differ in features such as possessive quantifiers (not in JavaScript), named-group syntax and some escapes. Re-test edge cases in the language you will use.
Why do I only get one match?
The g (global) flag is off. Without it JavaScript stops at the first match, and replace() changes only that one.
Why does . not match across lines?
By default the dot excludes line breaks. Tick s (dotAll), or use [\s\S] instead of the dot.
Why did my pattern time out?
Nested quantifiers such as (a+)+$ can backtrack for a long time. Execution runs in a worker and stops after two seconds. Shorten the input or simplify the pattern, then calculate again.
Sources
Last updated: 2026-10-30