Regex tester / pattern library
Regex: semantic version
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[\da-z-]+(\.[\da-z-]+)*)?(\+[\da-z-]+(\.[\da-z-]+)*)?$/i Test it live How it works
major.minor.patch with no leading zeros — (0|[1-9]\d*) allows 0 but rejects 01 — plus optional -prerelease and +build metadata suffixes, dot-separated.
Honest caveats
A simplified form of the official (much longer) semver.org regex: it accepts numeric prerelease identifiers with leading zeros, which strict semver forbids. Fine for matching versions in logs; use a semver library for comparisons.
Matches
1.0.02.10.3-beta.10.1.0+build.421.0.0-rc.1+sha.5114f85
Doesn't match
1.0v1.0.001.2.31.0.0-