18 ms·
Apparently it's an additional property "indices" on the returned array. > ..We propose the adoption of an additional indices property on the array result (the
by lioeters 6y ago
Apparently it's an additional property "indices" on the returned array.
> ..We propose the adoption of an additional indices property on the array result (the substrings array) of the RegExpBuiltInExec abstract operation (and thus the result from RegExp.prototype.exec(), String.prototype.match, etc.).
> This property would itself be an indices array containing a pair of start and end indices for each captured substring. Any unmatched capture groups would be undefined, similar to their corresponding element in the substrings array. In addition, the indices array would itself have a groups property containing the start and end indices for each named capture group.
> NOTE: For performance reasons, indices will only be added to the result if the d flag is specified.
https://github.com/tc39/proposal-regexp-match-indices https://github.com/tc39/proposal-regexp-match-indices
From given example:
const re1 = /a+(?<Z>z)?/d;
const s1 = "xaaaz";
const m1 = re1.exec(s1);
// indices are relative to start of the input string:
m1.indices[0][0] === 1;
m1.indices[0][1] === 5;
s1.slice(...m1.indices[0]) === "aaaz";