[GH-ISSUE #1049] Why suggested regexes have not used atomic groupings or possive quantifiers? #3360

Closed
opened 2026-04-25 17:42:59 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @LastKnightXZ on GitHub (Oct 6, 2024).
Original GitHub issue: https://github.com/semver/semver/issues/1049

In suggested regex like named group regex
^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

why are we not using atomic grouping or possessive like this
^(?>(?P<major>0|[1-9]\d*+))\.(?>(?P<minor>0|[1-9]\d*+))\.(?>(?P<patch>0|[1-9]\d*+))(?:-(?P<prerelease>(?:0|[1-9]\d*+|\d*+[a-zA-Z-][0-9a-zA-Z-]*+)(?:\.(?:0|[1-9]\d*+|\d*+[a-zA-Z-][0-9a-zA-Z-]*+))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]++(?:\.[0-9a-zA-Z-]++)*+))?$

note: added atomic grouping / possessive quantifiers all places i can think of, except for prerelease as we need to backtrack for prerelease segments with '0' as beginning, and it matches sames cases (do tell me if there are exceptions)

It would removes instances of unnecessary backtracking on mismatch,
and keeps thing clear which segments are not expected to backtrack.

Is it because many regex engine doesn't support atomic grouping / possessive quantifiers?

Originally created by @LastKnightXZ on GitHub (Oct 6, 2024). Original GitHub issue: https://github.com/semver/semver/issues/1049 In suggested regex like [named group regex](https://regex101.com/r/Ly7O1x/3/) `^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$` why are we not using atomic grouping or possessive like [this](https://regex101.com/r/yoWJvz/1) `^(?>(?P<major>0|[1-9]\d*+))\.(?>(?P<minor>0|[1-9]\d*+))\.(?>(?P<patch>0|[1-9]\d*+))(?:-(?P<prerelease>(?:0|[1-9]\d*+|\d*+[a-zA-Z-][0-9a-zA-Z-]*+)(?:\.(?:0|[1-9]\d*+|\d*+[a-zA-Z-][0-9a-zA-Z-]*+))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]++(?:\.[0-9a-zA-Z-]++)*+))?$` note: added atomic grouping / possessive quantifiers all places i can think of, except for prerelease as we need to backtrack for prerelease segments with '0' as beginning, and it matches sames cases (do tell me if there are exceptions) It would removes instances of unnecessary backtracking on mismatch, and keeps thing clear which segments are not expected to backtrack. Is it because many regex engine doesn't support atomic grouping / possessive quantifiers?
Author
Owner

@steveklabnik commented on GitHub (Oct 7, 2024):

Because the regexes are community contributed best efforts.

To be honest, I am kind of regretting including them. But, if you feel something is better, feel free to submit a PR.

<!-- gh-comment-id:2397863155 --> @steveklabnik commented on GitHub (Oct 7, 2024): Because the regexes are community contributed best efforts. To be honest, I am kind of regretting including them. But, if you feel something is better, feel free to submit a PR.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#3360