Are these valid numbers? #190

Closed
opened 2026-02-17 11:32:35 -06:00 by GiteaMirror · 6 comments
Owner

Originally created by @BartG95 on GitHub (Aug 19, 2015).

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.

Originally created by @BartG95 on GitHub (Aug 19, 2015). 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.
Author
Owner

@FichteFoll commented on GitHub (Aug 20, 2015):

1.0.0-0 is valid; the pre-release indentifier would be interpreted as non-numeric and cause lexicographical comparison with a different version it's just a zero.
1.0.0+some.build.metadata-beta is valid; -beta is part of the medatata-beta identifier, which in turn is part of the build metadata.

@FichteFoll commented on GitHub (Aug 20, 2015): `1.0.0-0` is valid; ~~the pre-release indentifier would be interpreted as non-numeric and cause lexicographical comparison with a different version~~ it's just a zero. `1.0.0+some.build.metadata-beta` is valid; `-beta` is part of the `medatata-beta` identifier, which in turn is part of the build metadata.
Author
Owner

@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.

@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.
Author
Owner

@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:

(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(((0|[1-9]\d*)|[1-9A-Za-z-][0-9A-Za-z-]*)\.)*((0|[1-9]\d*)|[1-9A-Za-z-][0-9A-Za-z-]*))?(\+(([0-9A-Za-z-]+)\.)*([0-9A-Za-z-]+))?
@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: ``` (0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(((0|[1-9]\d*)|[1-9A-Za-z-][0-9A-Za-z-]*)\.)*((0|[1-9]\d*)|[1-9A-Za-z-][0-9A-Za-z-]*))?(\+(([0-9A-Za-z-]+)\.)*([0-9A-Za-z-]+))? ```
Author
Owner

@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):

Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers MUST NOT include leading zeroes.

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-remaining is 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

@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): > Identifiers MUST comprise only ASCII alphanumerics and hyphen [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers MUST NOT include leading zeroes. 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-remaining` is 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
Author
Owner

@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.

@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.
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/semver#190