@@ -73,22 +73,23 @@ func (v Version) String() string {
7373// of the form "vMAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]". This
7474// conforms to https://semver.org/spec/v2.0.0.html
7575var versionRE = regexp .MustCompile (
76- `^ v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-.]+)?(\+[0-9A-Za-z-.]+|)?$ ` ,
76+ `v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-.]+)?(\+[0-9A-Za-z-.]+|)?` ,
7777 // ^major ^minor ^patch ^preRelease ^metadata
7878)
7979
8080// numericRE is the regexp used to check if an identifier is numeric.
8181var numericRE = regexp .MustCompile (`^(0|[1-9][0-9]*)$` )
8282
83- // Parse creates a version from a string. The string must be a valid semantic
83+ // Parse creates a version from a string. The string must contain a valid semantic
8484// version (as per https://semver.org/spec/v2.0.0.html) in the format:
85- // "vMINOR.MAJOR .PATCH[-PRERELEASE][+METADATA]".
85+ // "vMAJOR.MINOR .PATCH[-PRERELEASE][+METADATA]".
8686// MINOR, MAJOR, and PATCH are numeric values (without any leading 0s).
8787// PRERELEASE and METADATA can contain ASCII characters and digits, hyphens and
8888// dots.
89- func Parse (str string ) (* Version , error ) {
90- if ! versionRE .MatchString (str ) {
91- return nil , errors .Errorf ("invalid version string '%s'" , str )
89+ func Parse (fullStr string ) (* Version , error ) {
90+ var str string
91+ if str = versionRE .FindString (fullStr ); len (str ) == 0 {
92+ return nil , errors .Errorf ("invalid version string '%s'" , fullStr )
9293 }
9394
9495 var v Version
0 commit comments