Created
February 13, 2011 01:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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