Common use cases
- ✓Package and release validation
- ✓CI/CD version checks
- ✓Migration and dependency tooling
Validate semantic-version strings with numeric MAJOR.MINOR.PATCH components plus optional prerelease identifiers and build metadata. The pattern rejects leading zeros in numeric version components while allowing standard dot-separated prerelease and build identifiers.
^(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-]+)*))?$Flags: none
Enter one value per line. Each line is tested against the whole-string pattern using the browser JavaScript RegExp engine.
1.0.02.1.3-beta.10.1.0+build.421.0.0-rc.1+sha.abc1231.001.2.31.2.3-v1.2.3A SemVer validator should require exactly MAJOR.MINOR.PATCH, reject leading zeros in numeric identifiers, and separately handle optional prerelease and build metadata. A loose \d+\.\d+\.\d+ pattern misses those rules.
1.0.02.1.3-beta.10.1.0+build.421.0.0-rc.1+sha.abc1231.001.2.31.2.3-v1.2.3Yes. Values such as 2.0.0-beta, 2.0.0-beta.1, and 2.0.0-rc.1 are supported.
The regex only validates the syntax. If you need to sort or compare versions, use SemVer-aware comparison logic rather than string comparison.
The leading v is a common tag prefix, but it is not part of the SemVer version string. Strip the prefix before validating if your workflow uses v-prefixed tags.
Move from a live JavaScript regex test to capture-group inspection, flag behavior, literal escaping, focused pattern references, and debugging guides without treating each regex task as an isolated page.