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

Feature Request: Support in-pattern named groups #53

Open
KyNorthstar opened this issue Jun 3, 2021 · 0 comments
Open

Feature Request: Support in-pattern named groups #53

KyNorthstar opened this issue Jun 3, 2021 · 0 comments

Comments

@KyNorthstar
Copy link

KyNorthstar commented Jun 3, 2021

I'd love to have this support the same named groups that NSRE supports, like this:

// NSRegularExpression
try! NSRegularExpression(pattern:
        "^(?<major>\\d+)\\." +
        "(?<minor>\\d+)\\." +
        "(?<patch>\\d+)" +
        "(?:-(?<preRelease>(?:(?<preReleaseId>[0-9A-Za-z-]+)\\.?)+))?" +
        "(?:\\+(?<build>(?:(?<buildId>[0-9A-Za-z-]+)\\.?)+))?$",
        options: [])

// Crossroad Labs Regex
try! Regex(pattern:
        "^(?<major>\\d+)\\." +
        "(?<minor>\\d+)\\." +
        "(?<patch>\\d+)" +
        "(?:-(?<preRelease>(?:(?<preReleaseId>[0-9A-Za-z-]+)\\.?)+))?" +
        "(?:\\+(?<build>(?:(?<buildId>[0-9A-Za-z-]+)\\.?)+))?$",
        groupNames: "major", "minor", "patch", "preRelease", "preReleaseId", "build", "buildId")

This feels fragile to me; I feel like it might easily slip so that one group's name doesn't represent the intended group, and that might be subtle enough to not catch in testing.

It's also silly because it accepts the same syntax for in-pattern group names that NSRegularExpression accepts, without using it.

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