ecma262
ecma262 copied to clipboard
Normative: allow duplicate named capture groups
This allows you to have a regex like
/(?<year>[0-9]{4})-[0-9]{2}|[0-9]{2}-(?<year>[0-9]{4})/
where a capturing group name is re-used across alternatives. It continues to be illegal to re-use a name within the same alternative.
~~As currently specified, it also enforces that named backreferences correspond to capturing groups in the same alternative, which would make the following (currently legal) program illegal:~~
/(?<a>x)|\k<a>/
~~There is no reason to write this because the \k can never refer to anything, meaning it will always match the empty string. For this reason I think it should have been illegal in the first place. But if we want to preserve that behavior, it's easy enough to specify.~~
EDIT: updated so that the above remains legal, per plenary.
(I have a proposal repo for this, but figured it might as well be a PR.)
Happy do defer the editorial review, I'm told there've been enough eyes on this.