I am struggling with creating a regular expression to extract the main domain name from a URL. The URLs I have are:
http://domain.com/return/java.php?hello.asp
http://www.domain.com/return/java.php?hello.asp
http://blog.domain.net/return/java.php?hello.asp
http://us.blog.domain.co.us/return/java.php?hello.asp
http://domain.co.uk
http://domain.net
http://www.blog.domain.co.ca/return/java.php?hello.asp
http://us.domain.com/return/
From these examples, I want to only retrieve domain as the output of my regular expression. How can this be achieved? My current attempt is:
var url = urls.match(/[^.]*.(com|net|org|info|coop|int|co\.uk|org\.uk|ac\.uk|uk)/g);
However, this does not work for:
http://domain.net
If you have any suggestions or solutions, please help me out.