How to Test & Debug Regular Expressions
Enter your regular expression pattern and flags (such as gm or gi), paste sample text into the test corpus, and optionally provide a replacement template using $1, $2 capture group references. The inspector lists every match index, extracted capture group, plain-English token explanation, and live replacement output.
Key Features & Capabilities
- Evaluate ECMAScript regular expressions with g, i, m, s, u, and y flags against multi-line test corpuses
- Inspect match indices and numbered capturing groups alongside live replacement previews
- Read automated plain-English explanations of anchors, character classes, groups, and quantifiers
- Load battle-tested presets for emails, HTTPS URLs, IPv4 addresses, ISO dates, and semantic versions
Mastering ECMAScript Regular Expressions & Capture Groups
Regular expressions provide a concise declarative language for validating user input, scraping structured tokens from unstructured logs, and executing complex search-and-replace refactorings across codebases. Testing edge cases interactively prevents catastrophic backtracking and false positives before deploying validation rules to production.
| Token / Flag | Category | Behavior & Meaning | Example Pattern |
|---|---|---|---|
^ and $ | Anchors | Match start and end of string (or line when m flag is active) | ^\d{4}-\d{2}-\d{2}$ |
\d, \w, \s | Character Classes | Digit [0-9], word char [A-Za-z0-9_], or whitespace | \w+@\w+\.\w+ |
+, *, ?, {n,m} | Quantifiers | 1+, 0+, 0 or 1, or between n and m repetitions | https?:\/\/ |
(...) vs (?:...) | Groups | Numbered capturing group ($1) vs non-capturing group | (\d{3})-(?:\d{4}) |
g, i, m, u | RegExp Flags | Global (all matches), Case-insensitive, Multiline, Unicode | /pattern/gmu |
Avoiding Catastrophic Backtracking (ReDoS)
Nested quantifiers—such as (a+)+ or overlapping wildcard groups like (.*a){10}—can cause exponential execution time when evaluated against non-matching strings, leading to Regular Expression Denial of Service (ReDoS). Prefer specific character classes (like [^"\r\n]+) over greedy dot-star (.*) patterns whenever possible.
Frequently Asked Questions
Why does my regex only return the first match?
Make sure the global flag ("g") is included in the Flags input field. Without "g", RegExp.prototype.exec() stops after finding the first match.
How do I use capture groups in the Replacement String field?
Wrap the part of your pattern you want to extract in parentheses (...) and reference it in the replacement field as $1, $2, etc. For example, matching (\w+)@(\w+\.\w+) with replacement "[REDACTED@$2]" masks usernames while keeping the domain.
What does the "m" (multiline) flag change?
By default, ^ and $ match only the very start and end of the entire text box. Adding the "m" flag makes ^ and $ match the start and end of every individual line.