This proposal adds a new `.indices` property to the result array object returned by RegExp.prototype.exec and String.prototype.match. This property is an indices array containing a pair of start and end indices for each captured substring. As producing this array is expensive, the `.indices` property is only present when the /d flag is passed.
The result Array from RegExp.prototype.exec contains information about the substrings that were matched by the regular expression. While it already contains the input string, the index at which the pattern matched, and a groups object containing the substrings for any named capture groups, this information may be insufficient for advanced scenarios like reporting errors that highlight the offending substring. This feature bridges the gap by providing a `.indices` property, an Array that contains a pair of start and end indices for each captured substring.
Status in Chromium
Enabled by default (tracking bug) in:
- Chrome for desktop release 90
- Chrome for Android release 90
- Chrome for iOS release 90
- Android WebView release 90
Consensus & Standardization
Last updated on 2021-06-09