Regex Tester (safe, basic) — What this calculator does
This calculator lets you test a JavaScript regular expression (regex) against a block of text and immediately see
where it matches, what it captures, and how a replacement would change the text. It is designed to be safe for the browser
by limiting input size and stopping slow patterns before they freeze the page.
Main purpose
- Match mode: find matches of a regex inside the text and inspect their details.
- Replace mode: apply a replacement string and preview the replaced output.
What you input
-
Pattern — the regex pattern (written as plain text).
Example: \b(\w+)\b
-
Flags — common JavaScript flags:
g global: find all matches (not just the first)
i ignore case
m multiline anchors ^ and $
s dotAll: . can match newline
u unicode mode
y sticky matching
- Test text — the text where the regex is applied (paste it or load it from a file).
-
Replacement (only in Replace mode) — the replacement template.
You can use:
$1, $2, … for capturing groups, and $& for the whole match.
What you get as output
1) Visual match highlighting
The calculator produces a highlighted view of the text where each match is marked. Clicking a highlighted match selects it
and updates the group details.
2) Match timeline visualization
A compact timeline bar shows where matches occur across the full text. Matches near the start appear near the left,
and matches near the end appear near the right. This helps you see clustering, spacing, and coverage at a glance.
3) Match list
A table lists matches (bounded for performance), including:
- Match index (0, 1, 2, …)
- Position (starting index in the text)
- Length (number of characters matched)
- Matched text (preview)
4) Capturing groups
For a selected match, you get a table of:
- Group 0: the entire match
- Group 1..n: each capturing group value (from parentheses in your pattern)
Groups appear in the same order as the capturing parentheses in your pattern. Non-capturing groups like (?:...)
do not create group numbers.
5) Replace result (Replace mode only)
When Replace mode is enabled, the calculator shows the full replaced text and the number of replacements applied
(based on matches found, within safety limits).
Safety features (prevents freezing)
Some regex patterns can be extremely slow on certain inputs (a common issue called catastrophic backtracking).
This calculator includes safety controls so you can experiment without locking up the UI:
-
Max input length — trims very large text before running the regex to reduce worst-case work.
-
Timeout / stop if slow — executes regex work in a Web Worker and terminates it if it exceeds the time limit.
This prevents the main page from freezing.
-
Max matches — stops collecting matches after a limit to avoid huge outputs and expensive highlighting.
-
Warnings — shows heuristic warnings for patterns that often lead to slow performance (for example, nested quantifiers).
Practical tips
- Enable
g when you want a full list of matches. Without g, you often get only the first match.
- If your pattern is slow, try simplifying it (avoid nested
+/* quantifiers) or reduce input size.
- Use Replace mode to test cleaning/formatting rules, then copy the output for use elsewhere.
This tool uses the JavaScript RegExp engine available in the browser, so behavior matches what you would see in
JavaScript code running in the same environment.