$re = '/^XXX-\d{4}-((?![XYT])[A-Z]){4}$/m';
$str = 'XXX-0000-XBCD
XXX-0000-AXCD
XXX-0000-ABXD
XXX-0000-ABCX
XXX-0000-XXCD
XXX-0000-XBXD
XXX-0000-XBCX
XXX-0000-AXXD
XXX-0000-AXCX
XXX-0000-ABXX
XXX-0000-XXXX
XXX-0000-AB1D
XXX-0000-A%CD
XXX-0000-ABCDE
XXX-0000-ABCDX
AXXX-0000-ABCD
XXX-A0000-ABCD
XXX-0000-ABCD
';
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