Regex Tester, Debugger & Match Explainer

Test JavaScript regular expressions with real-time colored match highlighting, capture group extraction, string substitution, and common pattern presets. 100% browser-based.
Regular Expression Pattern & Flags
/ /
Presets:
Test String 0 Matches Found
Live Match Highlighting
Regex Substitution & Replace
-
Capture Groups & Match Details
# Full Match Offsets Captured Groups
No matches detected.

The Theoretical Architecture of Regular Expressions: NFAs & ReDoS Prevention

Invented in 1951 by American mathematician Stephen Cole Kleene to describe formal regular languages, regular expressions (regex) are formal string-matching patterns. In Chomsky's hierarchy of formal grammars, regular expressions define Type-3 grammars recognizable by finite-state automata.

1. DFA vs NFA Regex Engines

Modern programming languages employ one of two fundamental engine architectures:

2. Catastrophic Backtracking & ReDoS Vulnerabilities

A Regular Expression Denial of Service (ReDoS) attack exploits backtracking engines using patterns that exhibit ambiguous, nested quantifiers:

/^(a+)+$/

When matching a matching string like aaaaaaaaaa, the engine succeeds rapidly. However, when tested against a non-matching string like aaaaaaaaaaaaaaaaaaaaaaaaaaaa!, the engine attempts every permutation of dividing the a's across inner and outer plus operators. For an input of length $n$, the engine executes $O(2^n)$ steps, locking 100% of the CPU core for minutes or days, freezing Node.js event loops or web servers.

3. Capturing Groups vs Non-Capturing Groups

Parentheses in regular expressions create Capturing Groups by default (e.g. (abc)). The JavaScript engine allocates memory buffers to track the start index, end index, and matched string for each group, accessible via $1, $2, etc.

If you only need grouping for precedence or quantifiers without extraction, always use Non-Capturing Groups ((?:abc)):

// Inefficient: allocates memory for 3 unused capture groups
/(http|https|ftp):\/\/([a-z]+)\.([a-z]+)/

// Optimized: zero capture allocation overhead
/(?:https?|ftp):\/\/([a-z]+)\.([a-z]+)/

4. Zero-Width Lookahead & Lookbehind Assertions

5. Frequently Asked Questions (FAQ)

Why does my global regex behave inconsistently when called multiple times in JavaScript?
When a regex object uses the global flag g, the JavaScript engine stores internal state on the regex object's lastIndex property. Subsequent calls to regex.test(str) resume searching from the previous match's end index instead of the beginning. Reset regex.lastIndex = 0 or use a fresh regex instance to ensure deterministic results.
Are my test strings or patterns stored or transmitted?
No. All pattern compilation, string matching, and capture group extraction execute locally inside your browser via your device's native V8 JavaScript runtime.
Can I use named capture groups in this tool?
Yes. Modern JavaScript supports named capture groups using the (?<name>...) syntax, accessible in substitutions via $<name>.

Security Verification

Copied to clipboard!

We use cookies to enhance your browsing experience, serve personalized ads, and analyze traffic in compliance with GDPR and CCPA. Read our Privacy Policy.