Skip to content

Instantly share code, notes, and snippets.

@leszekgruchala
Created April 6, 2012 08:10
Show Gist options
  • Save leszekgruchala/2318068 to your computer and use it in GitHub Desktop.
Save leszekgruchala/2318068 to your computer and use it in GitHub Desktop.
Parser taken from JQuery Mobile, left just parser of URL
//Taken from JQuery Mobile
path = {
urlParseRE: /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,
parseUrl: function( url ) {
var matches = path.urlParseRE.exec( url || "" ) || [];
return {
href: matches[ 0 ] || "",
hrefNoHash: matches[ 1 ] || "",
hrefNoSearch: matches[ 2 ] || "",
domain: matches[ 3 ] || "",
protocol: matches[ 4 ] || "",
doubleSlash: matches[ 5 ] || "",
authority: matches[ 6 ] || "",
username: matches[ 8 ] || "",
password: matches[ 9 ] || "",
host: matches[ 10 ] || "",
hostname: matches[ 11 ] || "",
port: matches[ 12 ] || "",
pathname: matches[ 13 ] || "",
directory: matches[ 14 ] || "",
filename: matches[ 15 ] || "",
search: matches[ 16 ] || "",
hash: matches[ 17 ] || ""
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment