Skip to content

Instantly share code, notes, and snippets.

@kiquetal
Created August 19, 2014 16:40
Show Gist options
  • Save kiquetal/eb0e3fc4c0823f025eca to your computer and use it in GitHub Desktop.
Save kiquetal/eb0e3fc4c0823f025eca to your computer and use it in GitHub Desktop.
parturl
http://www.coderholic.com/javascript-the-good-parts/
var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
var url = 'http://www.ora.com:80/goodparts?q#fragment';
var result = parse_url.exec(url);
var names = ['url', 'scheme', 'slash', 'host', 'port', 'path', 'query', 'hash'];
var blanks = ' ';
var i;
for (i = 0; i < names.length; i += 1) {
document.writeln(names[i] + ':' + blanks.substring(names[i].length), result[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment