$re = '/(?<type>\w*)\/(?<tree>([\w\-]+\.)+)?(?<subtype>[\w\-]+)(\+(?<suffix>[\w\-\.]+))?(; (?<parameter>[\w+-\.=]+))?/';
$str = 'text/html; charset=UTF-8
application/x-executable
application/graphql
application/javascript
application/json
application/ld+json
application/msword
application/pdf
application/sql
application/vnd.api+json
application/vnd.ms-excel
application/vnd.ms-powerpoint
application/vnd.oasis.opendocument.text
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/x-www-form-urlencoded
application/xml
application/zip
application/zstd
audio/mpeg
audio/ogg
image/gif
image/apng
image/flif
image/webp
image/x-mng
image/jpeg
image/png
multipart/form-data
text/css
text/csv
text/html
text/php
text/plain
text/xml';
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