Identifiersflags: g
Semantic Version (SemVer)
Match semantic version strings like 1.2.3, 1.2.3-beta.1, or 1.2.3+build.42.
Try it in RegexProPattern
regexJavaScript
/(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?(?:\+[\w.]+)?/gRaw source: (?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?(?:\+[\w.]+)?
How it works
Three numeric components (no leading zeros) separated by dots. Optional pre-release label after - and optional build metadata after + per the SemVer 2.0.0 spec.
Examples
Input
1.0.0Matches
1.0.0
Input
2.3.1-beta.1Matches
2.3.1-beta.1
Input
1.0.0+build.42Matches
1.0.0+build.42
Common use cases
- Package version validation
- Changelog parsing
- Dependency version extraction
- CI/CD pipeline version tagging