>_ MoriDev dev.moritools.com
ECMAScript RegExp 100% Client-Side · Zero Upload

JavaScript Regex Tester & Capture Group Debugger

Highlight live ECMAScript regex matches, inspect numbered and named (?<name>) capture groups, preview replacements, and flag ReDoS backtracking risks.

Ready (Offline)
Quick Summary

Write any ECMAScript regular expression and flag combination (g, i, m, s, u) to highlight every match inline, inspect numbered ($1) and named (?<group>) captures in a structured table, test string replacements, and catch nested-quantifier ReDoS risks.

Debugging complex log parsers, router matchers, or input validators by trial-and-error inside unit tests slows iteration down—and deploying an unchecked nested-quantifier regex to Node.js can stall the single-threaded event loop via catastrophic backtracking (ReDoS).

This client-side debugger executes against the exact ECMAScript RegExp engine built into your browser, guards against infinite zero-width match loops, times execution in milliseconds, and warns proactively when patterns contain dangerous nested quantifiers like (a+)+.

JavaScript RegExp Bugs & Security Traps

01. Catastrophic Backtracking (ReDoS) Freezing Node.js

Patterns such as ^([a-zA-Z0-9]+)+$ or (.*a){20} evaluate exponentially many paths on non-matching input, hanging a Node.js worker for seconds on a 35-character string. Rewrite with mutually exclusive character classes.

02. Stateful lastIndex Surprises With the /g Flag

Calling regex.test(str) repeatedly on a shared /g RegExp advances lastIndex across calls, making alternating calls return false unexpectedly. Reset lastIndex = 0 or drop /g when checking single strings.

03. Forgetting /s (dotAll) or /u (Unicode) Flags

By default, "." does not match newlines unless /s is enabled, and surrogate-pair emoji count as two code units unless /u (Unicode mode) is active.

ECMAScript Flag & Group Quick Reference

Flag / Syntax Behavior Example
g (global) Finds all matches instead of stopping at first /\d+/g
i (ignoreCase) Case-insensitive character matching /error/gi
m (multiline) ^ and $ match line starts/ends, not just full string /^WARN/gm
s (dotAll) Allows "." to match \n and \r line terminators /start.*end/s
(?<name>...) Named capture group accessible via match.groups (?<year>\d{4})-(?<month>\d{2})
(?:...) Non-capturing group for cleaner group numbering (?:https?://)

Worked Engineering Examples

Extracting Structured Fields From Application Logs

Input
Pattern: (?<level>ERROR|WARN)\]\s+req_id=(?<req>[a-f0-9]+) · Flags: g
Output
Match 1: level="ERROR", req="9f81c2" · Match 2: level="WARN", req="3b7a10"

Named capture groups self-document the pattern and populate structured columns in the capture table.

Detecting Nested Quantifier ReDoS Risk

Input
Pattern: ^([a-z0-9_]+)+$
Output
ReDoS Warning: nested quantifiers like (a+)+ can trigger exponential backtracking

Replacing ([a-z0-9_]+)+ with ^[a-z0-9_]+$ matches the exact same strings in linear O(n) time.

Frequently Asked Questions

How does the tester prevent infinite loops on zero-length matches like /a*/g?

Matching uses String.matchAll, which steps past zero-length matches (even between emoji in /u mode), and reports at most 500. Patterns run in a Web Worker that is terminated after 1.5 seconds, so a runaway pattern cannot freeze the page.

Can I test JavaScript .replace() backreferences like $1 or $<name>?

Yes. Fill in the optional Replacement input (for example "[$<level>] #$2") to preview the transformed string live alongside your matches.

Does JavaScript support lookbehind assertions like (?<=\$)\d+?

Yes. Modern ES2018+ engines (Chrome, Safari, Firefox, Node.js) support both positive (?<=...) and negative (?<!...) lookbehinds natively.

Are preset templates available for emails, UUIDs, IPv4, and SemVer?

Yes. Click any quick template chip above the pattern box to load battle-tested patterns and sample inputs instantly.

Continue Your Workflow

24 offline developer utilities