JavaScript Regex Tester
Inspect JavaScript regex matches, capture groups and positions in your browser.
Match results
Only a prefix is shown because the output limit was reached: at most 200 matches and 50,000 total code units of match/capture values. Reduce the pattern or sample text and test again.
Separate matches, captures and flags
A match is the text found by the whole pattern; captures are values taken by its parentheses. An optional group that did not participate is shown as null. namedGroups lists named captures separately.
The default g flag finds multiple matches. Without g, only the first is returned. The i/m/s/u flags change case, line boundaries, dot/newline and Unicode handling. Do not assume that another regex engine will produce identical results.
Check offsets with a small example
Example fills the pattern below, its text and the gi flags. The matches are cat 42 and CAT 7, with captures cat/42 and CAT/7. The first spans index 0 to end 6; the second follows the newline, spanning index 7 to end 12.
index/end are UTF-16 offsets with an exclusive end. For example, . with gu against 😀 returns one match spanning [0,2). Empty-string matches are retained, so an invisible match is different from no match.
Pattern: ([a-z]+)\s+(\d+)
Flags: gi
Text:
cat 42
CAT 7
Read time and output limits correctly
Testing runs in a separate Worker and is stopped after one second including startup. Timeout, syntax error and cancellation are not no-match results and do not count as successful runs. Editing or clearing the input also invalidates old Worker results.
Only a prefix is returned when 200 matches or 50,000 code units of match/capture values would be exceeded. If the first match has very large captures, the displayed count can even be zero. Read the limit warning and reduce the input or captures.
A completed test does not certify your application’s validation or security. Use JSON Validator for JSON grammar rather than substituting a regex, or Random String Generator when you need sample strings to test.
Regex and Worker references
Frequently Asked Questions
Does this reproduce Python or PCRE regex behavior?
No. It uses the current browser’s JavaScript RegExp engine. Syntax, flags and Unicode behavior can differ across engines, so also test in the one you will actually use.
Should I wrap my pattern in /.../gi?
No. Enter only the pattern body, and put options such as gi in the Flags field. You do not need to double backslashes as you would inside a JSON string.
What do index and end measure?
index is a zero-based UTF-16 start offset, and end is the exclusive end offset. An emoji can occupy two code units, so these offsets can differ from a visible-character count.
Does a timeout mean no matches were found?
No. It means the operation, including startup, did not finish within one second. A complex repeating pattern is stopped in its Worker; retry with less text or a simpler pattern.