$re = '/^(?:htt(?:ps|p):\/\/)?(.*com)(\/?.*)$/m';
$str = 'env1-www-uk.my.domain.com
env2-www-uk.my.domain.com
http://env1-www-uk.my.domain.com
http://env1-www-uk.my.domain.asd.net.com
https://env1-www-uk.my.domain.com
env1-www-uk.my.domain.com/something123
env2-www-uk.my.domain.com/some%20more/stuff-too/';
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