$re = '/(?<Fname>.*\.)(S(?<se>\d{1,2})E(?<ep>\d{2,3}).*|(?<yr>\d{4}[^p]).*)/m';
$str = 'Westworld.S04E05.720p.WEB.h264-KOGi[rarbg]
Westworld.S04E04.1080p.WEB.H264-CAKES[rarbg]
For.All.Mankind.S03E08.720p.WEB.h264-KOGi[rarbg]
Talk.to.Me.2022.1080p.WEBRip.DD5.1.x264-LAMA
Jules.2023.1080p.AMZN.WEBRip.DD5.1.x264-LAMA
';
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