$re = '/10\.(?:[0-9]|[0-1][0-9]?|20)\.0\.(?:25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[2-9][0-9]|1[1-9]|[1-9])/m';
$str = '10.0.0.1
10.19.0.13
10.22.0.13
10.20.0.2
10.0.0.6
10.24.0.1
10.19.0.233
10.18.0.13
10.17.0.12
10.0.0.12
10.0.0.211
10.3.0.123
10.4.0.121
10.5.0.200
10.5.0.201
10.5.0.1
10.4.0.0
10.4.0.254
10.0.0.12
10.9.0.134
10.10.0.112
10.20.0.254
10.20.0.1
10.20.0.9
10.19.0.19
10.18.0.18
10.13.0.1
';
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