$re = '/^(0|[1-9][0-9]{0,8}|[1-3][0-9]{9}|4[01][0-9]{8}|42[0-8][0-9]{7}|429[0-3][0-9]{6}|4294[0-8][0-9]{5}|42949[0-5][0-9]{4}|429496[0-6][0-9]{3}|4294967[0-1][0-9]{2}|42949672[0-8][0-9]|429496729[0-5])$/m';
$str = '0
1
2
123
999999999
1000000000
2000000000
3000000000
4000000000
5000000000
4500000000
4250000000
4270000000
4280000000
4290000000
4300000000
4295000000
4294000000
4294500000
4294600000
4294700000
4294800000
4294900000
4294950000
4294960000
4294970000
4294965000
4294966000
4294967000
4294968000
4294967500
4294967400
4294967300
4294967200
4294967250
4294967270
4294967290
4294967295
4294967296
1
0
-1
-4294967295
';
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