Regular Expressions 101

Community Patterns

Group separate name and version tag


Regular Expression
PCRE2 (PHP >=7.3)



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