$re = '/^[a-z](\d\d?|[a-z]\d[a-z\d]?|[a-z]?\d?\d \d[a-z]{2}|[a-z]\d [a-z] \d[a-z]{2})$/im';
$str = 'A0
B11
CC2
DD3D
EE44
F5 5FF
G77 7GG
HH8 8HH
II9 I 9II
JJ00 0JJ
00
0A
AA
111
1B1
11B
C1C
1CC
CCC
3333
D333
3D33
33D3
333D
E4E4
E44E
4EE4
4E4E
44EE
DDD3
D3DD
3DDD
DDDD
';
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