Take the tour ×  I have a standard URL e.g.   I am using
javascript in riak for map reduce and would like to only extract
www.test.com. So...the domain and the subdomain.  What is the
most efficient method to do this in js since I will have
millions of records?   share|improve this question Tricky, you
almost need a database of known domain name extensions because,
what happens if you have a url like... example.co.uk? ... A list
like this: mxr.mozilla.org/mozilla-central/source/netwerk/dns/…
–  Tim Joyce Dec 9 '12 at 10:25 Well...in python I did this.
remove http:// and split by /. This the domain was the first
element. Just need something in JS. –  Tampa Dec 9 '12 at 11:28
add comment  2 Answers  up vote 3 down vote accepted  Look at
this answer: http://stackoverflow.com/a/8498629/623400  var
matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); var
domain = matches && matches[1];  // domain will be null if no
match is found  Sophisticated domain matching is kinda tricky,
but all this is covered quite