$re = '/K\'(?|(?P<name1>81)\d+|(61)\d+|(64)\d+|(1(?:45|33)?)\d+|(44)\d+|(86)\d+|(678)\d+|(41)\d+|(49)\d+|(33)\d+|(685)\d+|(\d{1,3})\d+)/';
$str = 'K\'8134567
K\'81345678
K\'6134516789
K\'61345678
K\'643456
K\'646345678
K\'1234567890
K\'12345678901
K\'1454567890 <<<--- want 145 returned and not 1
K\'13345678901 <<<--- want 133 returned and not 1
K\'3214567890123
K\'32134567890123
K\'3654567890123
K\'8934567890123
K\'6554567890123
';
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