Skip to content

Instantly share code, notes, and snippets.

@mocheng
Created February 13, 2011 01:43
Show Gist options
  • Save mocheng/824331 to your computer and use it in GitHub Desktop.
Save mocheng/824331 to your computer and use it in GitHub Desktop.
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