$re = '/^(https?:\/\/)?([\w\Q$-_+!*\'(),%\E]+\.)+(\w{2,63})(:\d{1,4})?([\w\Q/$-_+!*\'(),%\E]+\.?[\w])*\/?$/m';
$str = 'http://google.com
https://google.com
http://www.google.com
www.google.com
www.google.de:8080
www.test123.de
www.domain.com.de.whatever.to
www.google
h4xx0!2.net
page.to
hallo.to/test/whatever
hallo.to/test/whatever.cgi
www.google.com/startpage.html/
www.google.!!!
www..com
http://blabla.computer.de/.......................';
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