Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate group names should be okay without warning when defined over a union #531

Open
mfulton26 opened this issue Dec 3, 2024 · 0 comments

Comments

@mfulton26
Copy link

MDN calls this out as valid in their valid cases:

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

RegExr gives a warning though:

(?<year> ERROR: Duplicate group name.
\d Digit. Matches any digit character (0-9).
{4} Quantifier. Match 4 of the preceding token.
)  

https://regexr.com/89hjl

If the duplicate group name weren't defined over a union with a | then I would agree with the warning but over a union is safe and can be very helpful in validating & parsing strings (e.g. instruction names with different arguments following them).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant