PatternRegex
Match a semantic version
Find semantic versions in changelogs, tags and dependency lists — MAJOR.MINOR.PATCH with optional prerelease suffixes like -rc.1.
Last updated
Matches
- 1.2.3
- 16.2.11
- 2.0.0-rc.1
Doesn’t match
- 1.2
- version two
Why it’s written this way
Three dot-separated digit runs is the semver core; the optional group tacks on a prerelease tag (-beta.2, -rc.1) using the identifier characters the spec allows.
The leading \b keeps it from starting mid-number, so the 6.2.11 inside 16.2.11 can't match on its own.
Edge cases to know
- →A four-part version (1.2.3.4) yields its first three parts as a match — extraction over text can't know where a version was supposed to end. Anchor when validating a lone field.
- →Build metadata (+20260904) isn't covered; the official full-strictness semver regex is five lines long, which is why this practical form exists.
- →A leading v (v1.2.3) is not part of the match — the version starts at the first digit.