mirror of
https://github.com/semver/semver.git
synced 2026-07-10 19:50:47 -05:00
[GH-ISSUE #266] Are these valid numbers? #4434
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 @BartG95 on GitHub (Aug 19, 2015).
Original GitHub issue: https://github.com/semver/semver/issues/266
Are these valid version numbers:
1.0.0-0 (not a leading zero, but just a zero as pre-release version identifier)
1.0.0+some.build.metadata-beta (pre-release version identifier and build metadata swapped)
I understand these versions are rare, but according the standard they are valid. (if read literally).I have to write a regex, so this need to be clarified.
@FichteFoll commented on GitHub (Aug 20, 2015):
1.0.0-0is valid;the pre-release indentifier would be interpreted as non-numeric and cause lexicographical comparison with a different versionit's just a zero.1.0.0+some.build.metadata-betais valid;-betais part of themedatata-betaidentifier, which in turn is part of the build metadata.@DavidFichtmueller commented on GitHub (Aug 20, 2015):
I agree, both are valid. If you need a RegEx to check, you can use this one: #232 . I hope this helps.
@BartG95 commented on GitHub (Aug 21, 2015):
Thanks! I already made an RegEx. According to that RegEx both are valid, I just wanted to make sure it is correct.
For completeness, here's my RegEx:
@DavidFichtmueller commented on GitHub (Aug 26, 2015):
Hey BartG95,
I compared your RegEx against mine and found one difference, where I think yours is not confirming to the specs. In section 9 (pre -release version):
The way I understand this, is that only pure numerical identifiers must not have a leading zero, but identifiers that are a mixture between numbers and letters can have a leading zero. So according to the specification
1.42.0-rc.0-bugs-remainingis a valid semver number, but it will not be (completely) captured by your RegEx.This is a minor thing, but I noticed it and wanted to let you know.
Cheers
David
@BartG95 commented on GitHub (Aug 28, 2015):
Thanks. I should have looked to this before: https://github.com/mojombo/semver/blob/master/semver.svg
I've update my RegEx to this:
(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:(?:\d*[A-Za-z-][0-9A-Za-z-]*|(?:0|[1-9]\d*))\.)*(?:\d*[A-Za-z-][0-9A-Za-z-]*|(?:0|[1-9]\d*))))?(?:\+((?:(?:[0-9A-Za-z-]+)\.)*[0-9A-Za-z-]+))?(http://regexr.com/3bm59)I also included non-capturing groups, which make it is easier to parse a version.
@DavidFichtmueller commented on GitHub (Aug 28, 2015):
Looks good. Nice use of non-capturing groups. And just in case you don't already know this classic, here is the XKCD about Regular Expressions: http://www.xkcd.com/208/ . Cheers.