$re = '/^\d(?=(?:-?\d){7}-?\d-\d$)\d*-\d+-\d*\d-\d$/m';
$str = '01-234-5678-9
01234-56-78-9
0123-4-5678-9
012-345-678-9
01-234567-8-9
01-234-5678-9
0-12345-678-9
0-123-45678-9
0-123-45678-9
01-23456-78-9
0-123456-78-9
0-1234567-8-9
No Match:
01-234-56788-9
01-234-568-9
01--2345678-9
01-2345678--9
0-1-23456789
-01-2345678-9
0-1238787456-78-9
0-123456-78-3439
0-123456-738-9
30-123456-78-9';
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