Semantic Version

Semantic versioning (major.minor.patch)

Live Tester— test the Semantic Version pattern
Pattern/^(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-]*))*))?$/

Should match →

Should not match →

Pattern

^(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-]*))*))?$

Matching examples

1.0.02.3.4-beta.1

Non-matching examples

1.0v1.0.0

Breakdown

(0|[1-9]\d*)\.
Major version
(0|[1-9]\d*)\.
Minor version
(0|[1-9]\d*)
Patch version
(?:-...)?
Optional pre-release

Related tools

Other patterns