JavaScript regex tester
Test JavaScript patterns against text and inspect matches, positions and capture groups.
- 1Add input
- 2Adjust settings
- 3Get your result
Tool input and files are processed in this browser without being uploaded.
Before you start
Try a JavaScript regular expression with your sample text. Review highlighted matches, captured groups and start/end offsets, then copy the complete JSON result.
How to use this tool
- Enter your sample in Test text, or load the example. An empty sample is allowed.
- Enter the pattern source and flags in their separate fields, then select Test expression. Do not wrap the pattern in /.../ delimiters.
- Check the highlighted text, positions and groups. Copy the JSON to keep all retained matches together with the sample text.
Supported inputs and limits
Patterns can use up to 4 KiB and test text up to 256 KiB, measured as UTF-8 bytes. The 2-second processing timeout starts when the Worker is ready. Loading has a separate 30-second timeout.
Start and end positions refer to the whole match and use zero-based UTF-16 code-unit offsets. The end offset points just after the match.
At most 1,000 matches are retained. The tool stops after retaining the 1,000th and sets capped; it does not check for a 1,001st match. Count reports the matches retained, so capped does not prove that more matches exist.
Worked example
Example input
ab12 cd34
Example options
{
"pattern": "(\\d+)",
"flags": "g"
}Example output
{
"matches": [
{
"index": 2,
"end": 4,
"text": "12",
"groups": [
"12"
],
"named": {}
},
{
"index": 7,
"end": 9,
"text": "34",
"groups": [
"34"
],
"named": {}
}
],
"capped": false,
"count": 2
}When something does not work
For an invalid expression, check the pattern and flags. If a size limit is reached, shorten the pattern or test text. For a processing timeout, simplify the expression or use a smaller sample, then test again. After cancelling, you can start a new test.
Frequently asked questions
Is my test text sent to a server?
Matching runs in a Worker in your browser. This tab may temporarily keep a recent draft while you switch tools, subject to cache limits. Refreshing or closing the tab clears it. Copy any result you want to keep; the copied JSON includes your sample text.
What do the result fields mean?
The copied JSON contains sample, matches, capped and count. Each match has a zero-based index, an exclusive end, matched text, numbered groups and a named-group object. Unmatched numbered groups are null; unmatched named entries are omitted from the JSON. Count is the number of retained matches.
Are empty inputs or zero-length matches allowed?
Yes. Empty pattern source and empty test text are valid. A zero-length match is recorded even though its text is empty. With g or y, repeating an empty match advances by one UTF-16 code unit, or by a surrogate pair when u is enabled. A count of 0 means no match was retained.
Documentation & further reading
Related tools
JSON formatter and string tools
Format or minify JSON, sort object keys, or convert between plain text and a JSON string.
Compare text
Compare two texts line by line, with a side-by-side view of changes.
HTML formatter
Format HTML source with consistent indentation and review the result as text.
CSS formatter
Reformat CSS into readable rules with consistent indentation and spacing.