Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
returns base url from a string url.
var u = 'www.loremipsum.com';
var p = /^(http:\/\/)?([^\/]+)/i
u.match(p)[2]
// http://www.loremipsum.com -> www.loremipsum.com
// www.loremipsum.com -> www.loremipsum.com
// www.loremipsum.com/dolor/sit/amet -> www.loremipsum.com
// http://www.loremipsum.com/dolor/sit/ -> www.loremipsum.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.