Last active
May 22, 2018 21:42
-
-
Save sharpjs/5482c67df9bda2a717979793c1e759a1 to your computer and use it in GitHub Desktop.
PowerShell/.NET Regular Expression for SemVer 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pubic Domain. No rights reserved. No warranty. | |
# Reference: | |
# https://github.com/semver/semver/blob/master/semver.md | |
$VersionRegex = [regex] '(?nx) | |
^ | |
(?<Version> | |
(?<Numbers> | |
( 0 | [1-9][0-9]* ) | |
( | |
\. | |
( 0 | [1-9][0-9]* ) | |
){2} | |
) | |
# Pre-release tag | |
( | |
- | |
( 0 | [1-9][0-9]* | [0-9]*[a-zA-Z-][0-9a-zA-Z-]* ) | |
( | |
\. | |
( 0 | [1-9][0-9]* | [0-9]*[a-zA-Z-][0-9a-zA-Z-]* ) | |
)* | |
)? | |
# Build metadata | |
( | |
\+ | |
[0-9a-zA-Z-]+ | |
( | |
\. | |
[0-9a-zA-Z-]+ | |
)* | |
)? | |
) | |
$ | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your regex doesn't match a single valid version string out of 35.
See: https://regex101.com/r/wk7CDs/1
See also a valid regex and related discussion: semver/semver.org#59 (comment)