Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

JS group names with same name

Open elibarzilay opened this issue 1 year ago • 2 comments

Bug Description

Duplicate capture group names are now a thing, would be nice to have them.

Reproduction steps

As seen on that page:

/(?<year>\d{4})-\d{2}|\d{2}-(?<year>\d{4})/;

Expected Outcome

Should work.

Browser

Chrome, and therefore "most browsers" :)

(But not yet in node, so not most of that world, yet.)

elibarzilay avatar Aug 05 '24 01:08 elibarzilay

So as long as the groups are in different alternatives, the group name may be repeated? Or is there a more complex rule to implement for this?

firasdib avatar Aug 09 '24 09:08 firasdib

That was it looks like -- that page says:

A more recent feature allows named capturing groups to share names, as long as they belong to different disjunction alternatives and cannot be matched at the same time (see browser compatibility for this).

elibarzilay avatar Aug 09 '24 16:08 elibarzilay

This will be supported in the next version.

firasdib avatar Jan 07 '25 13:01 firasdib

Thanks!

ebarzilay-godaddy avatar Jan 07 '25 14:01 ebarzilay-godaddy