$re = '/((?:(?:123456)|(?:1[2-5]*)|(?:[2-5]*6)) )/m';
$str = '12456 123456 34 1236 123456 1234 45 123456 whitings
14 356 124 6 12345 6 1245 malformations
12456 23456 2356 12345 12345 123456 6 furnishings
12456 34 34 356 12356 15 26 13 gastrointestinal
23456 1 234 3 5 12356 lawyer
2356 345 12345 4 4 1 6 gripped
1 236 145 23 16 4 12356 4 3 packers
1245 146 2 2 23 126 1235 2356 4 3 outrun
should not match ^
123456 123456 123456 123456 35 12456 123456 123456 23 356 23456 25 replenishes
3456 45 35 12456 1346 256 2356 123456 1236 123456 1346 flophouse
356 123456 56 12356 4 3 2356 6 12456 1246 12356 footsteps
123456 156 2356 136 123456 146 123456 5 12356 123456 1456 expurgations
12346 2 2346 123456 2356 56 245 12346 13456 12456 misidentifies
1256 345 24 12456 12356 123456 12356 356 1256 5 26 swine
123456 45 456 12346 136 12346 6 24 12346 4 56 235 extremists
346 1236 2356 13456 123456 23456 1346 1256 123456 24 346 245 hexagonal
14 23456 12356 1234 15 1456 1245 123456 23456 chrysanthemums
245 34 123456 123456 12 346 134 4 245 1245 146 6 gravitate
346 1245 136 23456 5 1356 123456 5 123456 123456 octettes
134 3456 15 15 46 34 123456 123456 3456 246 quasar
123456 35 123456 123456 123456 1245 123456 12456 1 surprisings
356 12346 1246 1235 4 12356 2 13456 13456 236 emptied
23456 2356 12456 134 2356 256 12456 12346 1 13 ennoblement
123456 235 16 5 13456 15 2 1456 12356 3456 3 123456 quadratic
should match ^';
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