Files
Philip ChimentoandGitHub 72e88149d1 Support indices.groups when compiling named groups in regexps (#15092)
Add support for indices.groups

If a RegExp has the /d flag (hasIndices), match objects should have an
extra property .indices with an array of the character indices that each
subgroup matched. The indices array itself has a property .groups giving
the matched character indices (or undefined) for each named capturing
group.

This doesn't do anything to enable support for the /d flag, the
hasIndices property, or the returned indices object, if the environment
does not support it, but it will populate .indices.groups in _wrapRegExp
if .indices is present, so that the
transform-named-capturing-groups-regex and
proposal-duplicate-named-capturing-groups-regex plugins can take
advantage of that support if it exists.
2022-10-31 21:15:49 +01:00

16 lines
315 B
JavaScript

var re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/d;
var result = re.exec("2017-12-23");
expect(result.indices.groups).toEqual({
year: [0, 4],
month: [5, 7],
day: [8, 10],
});
expect(result.indices.groups).toEqual({
year: result.indices[1],
month: result.indices[2],
day: result.indices[3],
});