$re = '/\b(?:(?=.{0,3}?\d)[A-Za-z\d]{4}\s??){3}\b/';
$str = '?K9X6 6GM6 LM11 // not recognized - but it should be
!K9X6 6GM6 LM11 // not recognized - but it should be
K0X6 0GM7 LM12! // not recognized - but it should be
K1X6 1GM8 LM13@ // not recognized - but it should be
K2X6 2GM9 LM14? // not recognized - but it should be
K3X6 3GM0 LM15# // not recognized - but it should be
K4X6 4GM1 LM16* // not recognized - but it should be
K5X65GM2LM17
bla bla bla
this shouldn\'t be visible
spod also shouldn\'t be visible
but line below should be!!
K9X66GM6LM11! (see that "!" at the end? Help me with this)
K5X65GM2LM17234324122323 //wrong, text is too long
A9D24 A12E A59E3 //wrong, text block counts 5 characters!
';
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