Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
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 PEP440 version. WARNING: This is a greedy regex and it might catch strings you don't expect it to, any number triggers it.

PEP440 documentation: https://www.python.org/dev/peps/pep-0440/

Submitted by anonymous - 6 years ago