Skip to content

Instantly share code, notes, and snippets.

@MiguelCastillo
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save MiguelCastillo/5820c402f77cdcea273e to your computer and use it in GitHub Desktop.

Select an option

Save MiguelCastillo/5820c402f77cdcea273e to your computer and use it in GitHub Desktop.
Regex to parse HTTP urls
// https://regex101.com/r/aH9kH3/21
function parseUrl (urlString) {
return /^((https?:)(\/\/\/?)(?:([\w]+)(?::([\w]*))?@)?([\d\w\.-]+)(?::(\d+))?)?([\/\\\w\.()-]*)?(?:([?][^#]*)?(#.*)?)*/gmi.exec(urlString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment