$re = '/^((25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(25[0-5]|2[0-4]\d|[01]?\d{1,2})$/m';
$str = '22.231.113.64
22.231.113.164
222.231.113.64
22.231.113.64
22.231.113.164
255.231.111.64
253.231.111.64
22.21.113.61
22.21.113.162
255.21.111.63
253.21.111.69
22.211.113.64
22.212.113.164
255.213.111.64
253.214.111.64
22.211.113.364
22.212.113.3164
255.213.111.464
253.214.111.564
not an ip address
not an ipv4 Address
Not an IPv5 Address';
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