$re = '/(\d{1,2})[^\d]{1,2}(\d{1,2})(?:[^\d]{1,2}(\d{1,2}))?.*/im';
$str = 'S01E02E03
01x01 Lorem ipsum.avi Result: 01, 01
01x01-02 Lorem ipsum.avi Result: 01, 02 Expected: 01, 01, 02
1x1 Lorem ipsum.avi Result: 1, 1
1x1-2 Lorem ipsum.avi Result: 1, 2 Expected: 1, 1, 2
S01E01.HDTV.x264-LOL.mp4 Result: 01, 01
S01E01E02.HDTV.x264-LOL.mp4 Result: 01, 02 Expected: 01, 01, 02
S01E01-02.HDTV.x264-LOL.mp4 Result: 01, 02 Expected: 01, 01, 02
S01E01-E02.HDTV.x264-LOL.mp4 Result: 01, 02 Expected: 01, 01, 02
';
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