Regex Tester
Develop and debug regular expressions with live testing against your sample text. Visual match highlighting shows exactly what matches. Inspect capture groups, test replacement strings, and toggle all JavaScript regex flags. A 200ms execution timeout prevents runaway patterns from freezing your browser.
What does this tool do?
The Regex Tester provides an interactive environment for developing JavaScript regular expressions. It offers live match highlighting in the test text, detailed inspection of capture groups (both numbered $1, $2 and named groups), all JavaScript regex flags (g global, i ignore case, m multiline, s dotAll, u unicode, y sticky), and a replacement mode to test regex substitutions with $1, $2 references. The interface catches common regex errors and prevents catastrophic backtracking with a 200ms timeout per execution.
How it works
The tool constructs a JavaScript RegExp object from your pattern string and selected flags. For matching, it uses RegExp.prototype.exec() in a loop for global matches or single execution for non-global. Matches are highlighted by calculating character positions in the text. Capture groups are extracted from the match array (index 0 is full match, 1+ are groups). For replacement, String.prototype.replace() is used with your replacement string that can reference $& (full match), $1-$99 (capture groups), $` (before match), $' (after match). A setTimeout-based watchdog interrupts execution if it exceeds 200ms, protecting against ReDoS (Regular Expression Denial of Service) patterns.
Features
- Live match highlighting in test text
- All match results with capture groups listed
- Toggle flags: g, i, m, s, u, y
- Replace mode: try replacement strings with $1/$2
- Catches malformed patterns with clear errors
- 200ms timeout prevents freezing from bad patterns
- JavaScript regex syntax (ES2018+ features supported)
How to use
- 1
Enter your pattern
Type the regex pattern without leading/trailing slashes — just the pattern body. Use standard JavaScript regex syntax.
- 2
Toggle flags as needed
g for global (find all matches), i for case-insensitive, m for ^/$ matching line start/end, s for dot matching newlines, u for Unicode, y for sticky matching.
- 3
Paste test text
Enter sample text that should match (and some that shouldn't). Matches highlight live as you edit. Click any match for details.
- 4
Review matches and groups
Each match shows the full text, position, and all capture groups. Use this to verify your pattern extracts the right data.
- 5
Test replacement (optional)
Switch to Replace mode to test substitution patterns. Use $1, $2 for capture group references, $& for full match.
Common use cases
Pattern development
Build and refine regex patterns for data validation, parsing, extraction, and text processing before adding to code.
Debugging regex issues
When a regex in your code behaves unexpectedly, paste it here with sample data to isolate the problem.
Data extraction planning
Develop patterns for log parsing, web scraping, or data cleaning by testing against real sample data.
Replacement strategy testing
Test find-and-replace patterns with capture groups before applying to large datasets or production code.
Tips & best practices
- Always test with edge cases: empty strings, strings that shouldn't match, and boundary cases
- The 's' (dotAll) flag is often overlooked — without it, the dot . doesn't match newlines, which surprises many developers
- Use non-capturing groups (?:...) when you don't need to extract the group content — they're more efficient
- Character classes like [a-z] inside a JavaScript regex with 'u' flag handle Unicode correctly; without 'u', they may not match non-ASCII letters