Skip to content

Instantly share code, notes, and snippets.

@rolfen
Created September 3, 2016 18:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolfen/17bf252d9fbf6d8e0d771269d9690ca3 to your computer and use it in GitHub Desktop.
Save rolfen/17bf252d9fbf6d8e0d771269d9690ca3 to your computer and use it in GitHub Desktop.
Deconstruct URL (quick regex)
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