mirror of
https://github.com/semver/semver.git
synced 2026-07-11 03:53:53 -05:00
[GH-ISSUE #1049] Why suggested regexes have not used atomic groupings or possive quantifiers? #2378
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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?
@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.