Created
September 5, 2012 23:41
-
-
Save tvpmb/3647795 to your computer and use it in GitHub Desktop.
Awesome Javascript URL Parsing
This file contains hidden or 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
parser.href = url; | |
var hostname2 = parser.hostname; | |
var search2 = parser.search; | |
/* | |
Notes: | |
- extremely slow | |
*/ |
This file contains hidden or 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
/* | |
Grabbed this from: http://jsperf.com/url-parsing | |
Referenced from this: https://gist.github.com/2428561 | |
*/ | |
<script> | |
Benchmark.prototype.setup = function() { | |
var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/; | |
var parser = document.createElement('a'); | |
var url = "http://jblas:[email protected]:8080/mail/inbox?msg=1234&type=unread#msg-content"; | |
}; | |
</script> |
This file contains hidden or 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
var matches = urlParseRE.exec(url); | |
var hostname1 = matches[11]; | |
var search1 = matches[16]; | |
/* | |
Notes: | |
- extremely fast | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment