Obtenez le sous-domaine de l'URL Javascript

url = "http://www.example.com/path/to/somwhere";
urlParts = /^(?:\w+\:\/\/)?([^\/]+)([^\?]*)\??(.*)$/.exec(url);
hostname = urlParts[1]; // www.example.com
path = urlParts[2];
Nice Nightingale