Skip to content

Use the same name of a capture group in different alternatives of disjunction (| operator) #1128

Closed as not planned
@fedy-cz

Description

@fedy-cz

It looks like the regex crate requires that all of the named capture groups have a unique name. Maybe it could allow use of the same name in different branches of the disjuction operator (|).

For example the javascript regex engine allows this (quote):

All names must be unique within the same pattern. Multiple named capturing groups with the same name result in a syntax error.
This restriction is relaxed if the duplicate named capturing groups are not in the same disjunction alternative, so for any string input, only one named capturing group can actually be matched. This is a much newer feature, so check browser compatibility before using it.

/(?<year>\d{4})-\d{2}|\d{2}-(?<year>\d{4})/;
// Works; "year" can either come before or after the hyphen

Could make some "simple parsers" a little bit nicer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions