Regular Expressions 101

Community Patterns

Group separate name and version tag

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^([\w\.]+)\s*\d[\d\.\-]*\w*
/
gm

Description

Here, ^ matches the start of the string, ([\w.]+) matches one or more word characters or dots and captures it in a group, \s* matches any whitespace between the name and version, \d[\d.-]* matches the version number (which starts with a digit and may contain digits, dots or hyphens), and finally \w* matches any additional characters at the end of the version number.

Submitted by anonymous - a year ago