$re = '@(?<category>\w+(?:-\w+)?)/(?<name>[a-z]+(?:[-_][a-z]+)?)-(?<version>\S+)@m';
$str = 'dev-libs/icu-63.1-r1 alpha amd64 arm arm64 ia64 ppc ppc64 x86 hppa s390
dev-libs/icu-layoutex-63.1 alpha amd64 ia64 ppc ppc64 x86 hppa sparc
dev-lang/perl-5.28-r1 s390
virtual/ruby_gems-0.3_pre24 amd64 x86
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php