Regex tester
Live matching, flags, and every capture group listed
Enter the pattern without surrounding / delimiters, add flags and supply text. Result offsets start at zero; timed-out calculations are stopped.
Example
Input
Pattern: (cat|dog) Flags: g Text: cat and dog
Example result
#0 "cat" $1 = "cat" #8 "dog" $1 = "dog"
Offsets start at zero. Do not include surrounding / delimiters in the pattern field.
Technical details & limits
Offsets count JavaScript UTF-16 code units. g finds all matches, i ignores case, m changes line anchors, s lets dot match newlines and u enables Unicode mode. Matching runs in a separate worker with a timeout to limit page blocking from backtracking; output is capped at 5000 matches.
About this tool
Test patterns with the browser's JavaScript regex engine. Inspect match offsets, complete matches and capture groups with g, i, m, s, u and y flags.
Use cases
- Sanity-check a regex before dropping it into a log-parsing script.
- Debug why an “almost working” regex fails on a specific line.
- Pull the values of named capture groups out to inspect structure.
How to use
- Enter the expression in Pattern without surrounding / delimiters.
- Enter flags in Flags: g (global), i (case-insensitive), m (multiline), s (dot-all), u (Unicode) or y (sticky). Use each at most once.
- Paste the target text in Text. Editing any field reruns the match.
Notes
Uses JavaScript’s RegExp engine, which differs in some corners from PCRE / Go / Java (backtracking, atomic groups, conditionals). Ultimately test in your target language.
FAQ
- How do the g and i flags work in JavaScript regex testing?
- The g flag finds all matches, while i makes matching case-insensitive. Matching a against Aa with gi returns 2 matches, whereas g alone returns 1. This tester follows JavaScript regular expression semantics, so another language may interpret flags or constructs differently. Check the pattern, flags, and sample text together, and verify behavior again in the environment where the expression will actually run.
- How many regular expression matches can this tester display?
- This tester displays at most 5000 matches and runs matching in a separate Worker with a timeout to limit blocking. Match positions use UTF-16 code units, so some characters occupy 2 position units. Split very large inputs into smaller cases when investigating a pattern. A timeout or truncated result list does not mean the complete input was successfully scanned, and omitted matches should not be interpreted as absent.
- Why can regex match positions differ from visible character counts?
- Regular expression positions use UTF-16 code unit indexes rather than visible character counts. A basic-plane character usually occupies 1 code unit, while a supplementary character occupies 2. Combining sequences can make the visual difference larger. Use the same indexing convention when locating a match in another editor or program, and do not substitute a UTF-8 byte offset for the position reported by the JavaScript matching engine.
Related tools