Created
January 27, 2015 15:20
-
-
Save balanza/264f3f1c1eb362c3a7ce to your computer and use it in GitHub Desktop.
Parse URL (including HTTP validation)
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 parseUrl = function(url) { | |
var r = /^((http[s]?|ftp):\/)?\/?(([\w\-\.]+):([\w\-\.\$]+)@)?([^:\/\s]+)((\/\w+)*?(:([0-9]+))\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/; | |
var tmp = r.exec(url); | |
return { | |
original: tmp[0], | |
protocol: tmp[2], | |
username: tmp[4], | |
password: tmp[5], | |
host: tmp[6], | |
port: tmp[10], | |
path: tmp[11], | |
query: tmp[12] | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment