Regular Expressions 101

Community Patterns

Version parsing

2

Regular Expression
PCRE (PHP <7.3)

/
(\d+)\.(\d+)(?:\.(\d+))?(?:\-(\w+))?
/
i

Description

Version parsing from following format: <major>.<minor>[.build][-postfix] Gets 4 groups: major, minor, build and postfix (last two only of they present in input string)

For example: 1.2.3456-SNAPSHOT gets major=1, minor=2, build=3456, postfix="SNAPSHOT"

Submitted by Ivkond - 8 years ago