Last active
October 24, 2018 15:18
-
-
Save peta/58a222cd25526bcf5188a4d517ab87c5 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
var urlParseRegex = /^(?:(?:(([^:\/#\?]+:)?(?:(?:\/\/)(?:(?:(?:([^:@\/#\?]+)(?:\:([^:@\/#\?]*))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/; | |
var results = urlParseRegex.exec('http://user:[email protected]:81/directory/file.ext?query=1#anchor'); | |
// Variable "results" now contains the fragments in the following order | |
var keysInOrderTheyAppear = [ | |
"href", // http://user:[email protected]:81/directory/file.ext?query=1#anchor | |
"origin", // http://user:[email protected]:81 | |
"protocol", // http: | |
"username", // user | |
"password", // pass | |
"host", // host.com:81 | |
"hostname", // host.com | |
"port", // 81 | |
"pathname", // /directory/file.ext | |
"search", // ?query=1 | |
"hash" // #anchor | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment