$re = '/^(?:https?:\/\/)?(?:(?:[\pL0-9-]+)\.)+[\pL]{2,}(?:\/.*)?$/imu';
$str = 'http://google.com
https://google.com
http://google.com/
https://google.com/
http://g oogle.com
http://google.com/somepath
https://g oogle.com/somepath
https://g_oogle.com/somepath
google.com
google.com/somepath
goo gle.com/badpath
кириллица.укр
кирилл ица.укр
кириллица.укр/путь
кирилл01ица.укр
кирилли-ца.укр/путь
собдомен.кириллица.укр
собдомен.кириллица.укр/путь
2саб.1саб.домен.укр
2саб.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