⚒️How it works

How does SemanVer work?

When SemVer.Parse() gets called with a semantic version string, it first checks the string against the SemVer compliance using the following regular expression (fetched from this). If it doesn't find any version element, such as the case of 1.0-1, it returns an error.

This is the regular expression used:

^(0|[1-9]\d*)\.(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-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

If there's a match, the next step is to extract the following information:

  • Major version (MajorVersion, int)

  • Minor version (MinorVersion, int)

  • Patch version (PatchVersion, int)

  • Pre-Release info (PreReleaseInfo, string)

  • Build metadata (BuildMetadata, string)

Finally, the parser creates a new class instance which holds all the parsed information.

Last updated