Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^[Pp]ython v?(?:(?:(?<epoch>[0-9]+)!)?(?<release>[0-9]+(?:\.[0-9]+)*)(?<pre>[-_\.]?(?<preLabel>(a|b|c|rc|alpha|beta|pre|preview))[-_\.]?(?<preNumber>[0-9]+)?)?(?<post>(?:-(?<postNumber0>[0-9]+))|(?:[-_\.]?(?<postLabel>post|rev|r)[-_\.]?(?<postNumber1>[0-9]+)?))?(?<dev>[-_\.]?(?<devLabel>dev)[-_\.]?(?<devNumber>[0-9]+)?)?)(?:\+(?<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))?$
/
gm

Description

Parses a python version which follows the PEP440 versioning scheme, obtained by calling the command python --version. This is done in an almost strict manner in order to avoid picking up undesired strings.

Submitted by anonymous - 6 years ago