Skip to content

Instantly share code, notes, and snippets.



Created Feb 13, 2011
What would you like to do?
With the help of regular expression, host name can be extracted from URL string in two lines.
* extract host name from URL string.
function getHost(url) {
var m = url.match(/^https?:\/\/([^\/:\d]+)/);
return m && m[1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment