views:

302

answers:

3

I want to get just the domain name(yahoo, google, stackoverflow) from the domain in javascript. How can I easily pull just this out and drop any subdomain and any extension?

See comment, I need it to work for any domain if possible.

+3  A: 
"www.google.com".match(/\.?([^.]+)\.[^.]+.?$/)[1]
Brian Campbell
+3  A: 
var domain = 'http://www.google.com/';
var parts = domain.toString().split('.'.toString());
parts[parts.length - 2];
Andrei Serdeliuc
+1  A: 

See how to get domain name from URL

Gumbo