What This Tool Does
This regex tester evaluates your regular expression against a test string and highlights every match in real-time. It supports all JavaScript regex flags (g, i, m, s, u, y), shows capture groups for each match, and reports match positions. Perfect for debugging patterns before using them in code.
Inputs Explained
- Pattern: Your regex pattern (without surrounding slashes).
- Flags: g (global), i (case-insensitive), m (multiline), s (dotall), u (unicode), y (sticky).
- Test String: The text to search.
- Replacement: Optional. If set, shows what String.replace would produce.
How It Works
The tool constructs a JavaScript RegExp with your pattern and flags, applies it to your test string with String.matchAll, and wraps every match in a highlighted span. Capture groups are extracted from each match and displayed with their position indices. Replacement preview uses String.replace.
Formula / Logic Used
Regex Tester & Debugger
Test and debug regular expressions with live match highlighting and capture group detail.
Step-by-Step Example
Pattern: \b\w+@\w+\.\w+\b | Flags: gi
Test: Contact alice@example.com or bob@test.co today.
Matches: 2 — alice@example.com (at index 8), bob@test.co (at index 29).
With replacement [EMAIL]: Contact [EMAIL] or [EMAIL] today.
Use Cases
- Build and validate patterns: Prototype regex before embedding in production code.
- Debug failing patterns: See exactly what your regex matches (or misses) and fix it quickly.
- Learn regex: Experiment with character classes, quantifiers, and groups with live feedback.
- Extract data: Pull emails, phone numbers, dates, or custom fields from free-text data.
- Replacement testing: Preview replacements with capture group references ($1, $2) before committing.
Assumptions and Limitations
- Uses JavaScript regex syntax — lookbehind (?<=) works in modern browsers but some regex features differ from PCRE/Python.
- Named capture groups (?
) are supported in modern browsers (2018+). - Very complex patterns on very large inputs may cause catastrophic backtracking; test with small inputs first.
- The tool shows up to 50 match details; the total count is always accurate.
Frequently Asked Questions
What regex flavor does this tool use?
JavaScript (ECMAScript) regex. Similar to PCRE but with some differences — no possessive quantifiers, named groups use (?
What do the flags mean?
g = global (find all matches, not just first); i = case-insensitive; m = multiline (^ and $ match line starts/ends); s = dotall (. matches newlines); u = unicode (full Unicode support); y = sticky (match from lastIndex only).
How do I use capture groups in replacement?
Wrap parts of your pattern in parentheses to capture them, then reference as $1, $2, etc. in replacement. Example: pattern (\w+) (\w+), replacement $2 $1 swaps every two words.
Why does my regex work here but fail in Python?
JavaScript and Python regex differ slightly. Python uses (?P
What is catastrophic backtracking?
Nested quantifiers like (a+)+ or .*.* can make a regex take exponential time on long strings. The tool runs in your browser, so a bad pattern may freeze the page. If it hangs, refresh and simplify the pattern.
How do I match special characters like . or +?
Escape them with a backslash: \. matches a literal period, \+ matches a literal plus. Characters that need escaping: . ^ $ * + ? ( ) [ ] { } | \ /.
Can I test multi-line regex?
Yes. Use the 'm' flag so ^ and $ match line starts/ends. Use 's' flag so . matches newlines too. Your test string can have as many lines as you want.
Is my pattern or test string stored?
No. Everything runs in your browser using native RegExp and String.matchAll. Nothing is sent to any server or stored.
Sources and References
- MDN — Regular Expressions — Comprehensive JavaScript regex reference.
- Regex101 — Multi-flavor regex debugger with detailed explanations.
- MDN — RegExp Reference — Full RegExp API reference.
- ECMAScript Specification — RegExp — Official regex syntax spec.