Originally created by @LastKnightXZ on GitHub (Oct 6, 2024).
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).
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?
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.
@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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @LastKnightXZ on GitHub (Oct 6, 2024).
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.