The string value to search.
A RegExp with the global flag set, a matcher value used to create a global
RegExp, or any object with a [Symbol.matchAll] method.
An IterableIterator<RegExpExecArray> where each RegExpExecArray contains:
[0] — the full matched substring[1..n] — captured groups (or undefined for unmatched optional groups).index — zero-based index of the match in value.input — the original string.groups — named capture groups object, or undefined if no named captures// Basic global regex — all matches with capture groups
const matches = [...strMatchAll("test1 test2 test3", /test(\d)/g)];
matches.length; // 3
matches[0][0]; // "test1"
matches[0][1]; // "1"
matches[0].index; // 0
matches[1][0]; // "test2"
matches[2][1]; // "3"
// Named capture groups
const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/g;
const dates = [...strMatchAll("2024-01-15 and 2025-06-30", re)];
dates[0].groups; // { year: "2024", month: "01", day: "15" }
dates[1].groups; // { year: "2025", month: "06", day: "30" }
The
strMatchAll()method returns an iterator of all results matching a string against a regular expression, including capturing groups. Unlike strMatch, it returns every match in the string (not just the first) and each result includes fullRegExpExecArraydetails: matched substrings, capture groups, the matchindex, and the originalinputstring.If
matcheris aRegExpit must have the global (g) flag set; a non-globalRegExpthrows aTypeError. Ifmatcheris not aRegExp, native behavior is followed by creating a globalRegExpfrom the matcher value (for example,"."matches any character andundefinedbehaves as an empty pattern).If
matcheris an object that implements[Symbol.matchAll], that method is called instead, allowing custom matcher objects to control the iteration.