Created
September 3, 2016 18:37
-
-
Save rolfen/17bf252d9fbf6d8e0d771269d9690ca3 to your computer and use it in GitHub Desktop.
Deconstruct URL (quick regex)
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
window.location.href.match(/^([^/]+):\/\/([^/:]+):?([1-9]*)\/([^?]*)\??(.*)$/) | |
Example output: | |
["http://127.0.0.1:1337/projects/sd?sdflkj&jh", "http", "127.0.0.1", "1337", "projects/sd", "sdflkj&jh"] | |
That is: full match, protocol, host, port, path (relative to root), query string | |
Todo: test for bugs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment