regex for semantic versioning
match a SemVer string
^(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-]+)*))?$
Regex Flags
global match
?
ignore case
?
multiline
?
dotAll
?
unicode
?
sticky
?
1
0.0.4
1.2.3
1.2
10.20.30
01.1.1
1.1.2-prerelease+meta
1.1.2+meta
9.8.7-whatever+meta+meta
1.0.0-alpha
1.0.0-alpha.beta
1.0.0-alpha.1
1.0.0-alpha.0valid
1.0.0-rc.1+build.1
1.2.3-beta
10.2.3-DEV-SNAPSHOT
1.2.3.DEV
1.2.3-0123
1.2.3-SNAPSHOT-123
1.0.0
2.0.0+build.1848
2.0.1-alpha.1227
1.0.0-alpha+beta
1.0.0-alpha_beta
1.2.3----RC-SNAPSHOT.12.9.1--.12+788
1.2.3----R-S.12.9.1--.12+meta
1.2-SNAPSHOT
1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788
Match a SemVer as specified in https://semver.org/
Semantic Versioning is a versioning system that has been adapted to bring sanity to the management of rapidly moving software release targets. This expression can be used to find or validate a semantic version numbers.
The basic expression has 3 numbers which represent Major Version, Minor Version and Patches.
Pre-release metadata is represented by appending a hyphen(-)
and the name.
Cheatsheet
expr | usage |
---|---|
/h.*llo/ | the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo" |
/\d/ | matches any digit |
/[0-9]/ | matches all digits |
/(?:hard)?work/ | matches "work" or "hardwork" but is a non-capturing group |
iHateRegex
by
geon