$re = '/(?<content>(?<type>.+?)\/(?<sub>.+?)(?:\+(?<suffix>.+?))?)(?:;.*?(?:q=(?<weight>[.\d]+))?.*?)?(?:,|$)/m';
$str = '*/*
text/html,application/json;q=0.9
application/json; charset=utf-8
application/json; xx=utf-8
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
application/javascript
application/x-www-form-urlencoded
application/ld+json
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.wordprocessingml.document
multipart/form-data
';
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