Regular Expressions 101

Community Patterns

There does not seem to be anything here

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

#
^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<build>\d+)(?:\.(?P<revision>\d+))?)?)?(?:-(?P<prerelease>\w+)(?:[-\.](?P<version>\d+))?)?$
#
gm

Description

Regex that parses a version number including prerelease information and captures Major, Minor, Build, Revision, Prerelease and Prerelease version.

Major is mandatory - Minor, Build and Revision can be omitted.

The whole Prelease part is optional - it can match any text value followed by a pre-release version separated from the info with either a . (dot) or a - (dash).

Submitted by Benny Tordrup - a month ago