There is an example on php.net how to get last two domain segments in two steps:
This piece of code:
$domain = 'http://www.php.net/index.html';
$url = parse_url($domain);
$tokens = explode('.', $url['host']);
print_r($tokens);
Will give you this data:
Array
(
[0] => www
[1] => php
[2] => net
)
I believe there is no need for regexs as far as it's very hard to properly parse URL with them. From resulting $tokens array you can extract any part of host name easily.
Update:
print_r($url);
$url array contains all necessary details:
Array
(
[scheme] => http
[host] => www.php.net
[path] => /index.html
)