Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
^(?'MAJOR'(?:0|(?:[1-9]\d*)))\.(?'MINOR'(?:0|(?:[1-9]\d*)))\.(?'PATCH'(?:0|(?:[1-9]\d*)))(?:-(?'prerelease'[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(?:\+(?'build'[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$
/
gm

Description

Semantic Versioning regex pattern according to Tom Preston-Werner

http://semver.org/

https://github.com/mojombo/semver/blob/master/semver.md

Substitutes http://regex101.com/r/gG8cK7/1 following discussion on semver https://github.com/mojombo/semver.org/issues/59

Submitted by @gvlx <Gerardo Lisboa> - 10 years ago