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
const matches = [...polyStrMatchAll("test1 test2", /test(\d)/g)];
matches.length; // 2
matches[0][0]; // "test1"
matches[0][1]; // "1"
matches[0].index; // 0
Polyfill implementation of
String.prototype.matchAll()that returns an iterator of all results matching a string against a regular expression, including capturing groups.Matches the behaviour of the native
String.prototype.matchAll()method:RegExpmatchermust carry the global (g) flag; passing a non-globalRegExpthrows aTypeError.RegExpmatcheris passed tonew RegExp(matcher, "g"), mirroring native behavior.matcherexposes a[Symbol.matchAll]method, that method is called with the coerced string value, mirroring the native delegation behaviour.lastIndexusing native-styleAdvanceStringIndexbehavior, including code-point advancement for unicode regexes.