Created
April 2, 2014 06:52
-
-
Save altmind/9929101 to your computer and use it in GitHub Desktop.
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
function parseUrl(url) { | |
if ($.type(url) === "object") { | |
return url; | |
} | |
var matches = /^(((([^:\/#\?]+:)?(?:\/\/((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?]+)(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/.exec(url); | |
return matches ? { | |
href:matches[0] || "", | |
hrefNoHash:matches[1] || "", | |
hrefNoSearch:matches[2] || "", | |
domain:matches[3] || "", | |
protocol:matches[4] || "", | |
authority:matches[5] || "", | |
username:matches[7] || "", | |
password:matches[8] || "", | |
host:matches[9] || "", | |
hostname:matches[10] || "", | |
port:matches[11] || "", | |
pathname:matches[12] || "", | |
directory:matches[13] || "", | |
filename:matches[14] || "", | |
search:matches[15] || "", | |
hash:matches[16] || "" | |
} : {}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment