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.0
  • 2.10.3-beta.1
  • 0.1.0+build.42
  • 1.0.0-rc.1+sha.5114f85

Doesn't match

  • 1.0
  • v1.0.0
  • 01.2.3
  • 1.0.0-

More patterns