Free tool

Regex Tester, Debugger & Explainer

Debug regular expressions in real time with live match highlighting, named capture group inspection, string replacement previews, token explanations, and ReDoS backtracking detection.

Regex Tester, Debugger & Explainer: the tool

Production Presets:
//gi
2 matches found|ReDoS Audit: No catastrophic backtracking patterns detected
Flags: gi
Test String
Live Highlighted MatchesHover highlighted pill for match #
Contact engineering@deesu.dev or billing+eu@acme-corp.co.uk. Invalid examples: user@, @domain.com, plain-text.
Match #1engineering@deesu.dev
index 8–29 (21 chars)
$<user>engineering
$<domain>deesu.dev
Match #2billing+eu@acme-corp.co.uk
index 33–59 (26 chars)
$<user>billing+eu
$<domain>acme-corp.co.uk

Hardening input validation, parsers, or security pipelines in production?

DEESU builds resilient backend APIs, high-throughput log pipelines, and security-audited validation layers for modern SaaS teams.

Talk to Our Engineers

How it works

How JavaScript Regular Expressions Execute Under the Hood

Modern JavaScript engines like V8 (Chrome, Node.js, Cloudflare Workers) and JavaScriptCore execute regular expressions using an NFA (Nondeterministic Finite Automaton) backtracking engine called Irregexp. Unlike pure DFA engines such as RE2, a backtracking NFA supports powerful features including backreferences, named capture groups, and arbitrary lookbehind assertions.

Every time your pattern encounters an alternation (a|b) or a quantifier (+, *, {m,n}), the engine pushes a choice point onto an internal stack. If the remainder of the pattern fails to match later in the input string, the engine pops the stack and tries the next branch. Visual inspection of matches, capture indices, and individual tokens makes this execution model transparent so you can verify edge cases before shipping code to production.

Understanding ReDoS (Regular Expression Denial of Service)

Because backtracking engines exhaustively explore alternative paths on failing inputs, a poorly constructed regex can turn a 40-character HTTP header or form input into a multi-second CPU lockup. In single-threaded runtimes like Node.js or browser main threads, one malicious input string stalls every concurrent request.

Our built-in ReDoS auditor inspects your regular expression statically for the most common catastrophic backtracking structures used in real-world CVEs:

  • Nested Quantifiers: Patterns like (a+)+ or ([a-zA-Z0-9]+)*$ create exponential O(2^n) backtracking when a trailing character fails to match.
  • Overlapping Alternations Under Repetition: Expressions like (\w|[a-z])+ allow the same character to match multiple branches, multiplying decision states.
  • Multiple Unbounded Wildcards: Adjacent .* or .+ clauses cause quadratic O(n^2) scans across long logs, stack traces, or untrusted HTML snippets.
  • Practical Mitigation: Replace greedy wildcards with mutually exclusive negated character classes (such as [^/]+), enforce input length limits before calling .test(), and keep quantifiers flat.

Mastering Capture Groups, Lookarounds, and Replace Rules

Named capture groups ((?<year>\d{4})) dramatically improve code readability over fragile numeric indices ($1, $2). When refactoring strings with String.prototype.replace(), named tokens like $<year> remain stable even if you insert an extra group earlier in the pattern. Non-capturing groups ((?:...)) let you group alternations or quantifiers without polluting the match array.

Lookaheads ((?=...), (?!...)) and lookbehinds ((?<=...), (?<!...)) are zero-width assertions: they verify surrounding context without consuming characters into the matched slice. Password strength validators, currency formatters, and log redactors rely heavily on lookarounds to enforce multiple independent constraints in a single pass.

Choosing the Right Regex Flags for Production Code

Flags fundamentally alter how a regular expression scans text. Always include the u (Unicode) flag when validating international names, emoji, or user-generated text so surrogate pairs are treated as single code points instead of broken UTF-16 halves. Be careful with stateful /g regex instances stored in module scope: calling .test() repeatedly mutates regex.lastIndex, causing alternating false negatives unless you reset lastIndex = 0 or omit g for boolean checks.

FAQ

Questions, answered

No. Every match highlight, capture group inspection, string replacement, and ReDoS audit runs 100% locally in your browser using the native JavaScript RegExp engine. Sensitive logs, tokens, or PII never leave your device.

That symptom is classic catastrophic backtracking (ReDoS), usually caused by nested quantifiers such as (\w+)+ or overlapping alternations inside a repeated group. Check the ReDoS Auditor tab in this tool to pinpoint the risky subpattern and replace it with a negated character class.

Use $<groupName> syntax in your replacement string (for example $<day>/$<month>/$<year>). You can also use numbered references like $1 and $2, or $& to insert the entire matched substring.

Greedy quantifiers consume as many characters as possible before backtracking, whereas lazy quantifiers (+?, *?, ??) match as few characters as possible. For example, <.+> matches from the first < to the very last >, while <.+?> stops at the first closing >.

By default, ^ and $ only match the very beginning and end of the entire input string, and . does not match newline characters. Enabling /m makes ^ and $ match every line boundary, while /s allows . to match across line breaks.

More free tools

Reply within 1 business day

Tell us what you're building.

Send the problem, not a polished brief. We'll tell you what it actually takes to ship it: stack, timeline and cost, before you commit to anything.