Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Javascript URL parsing regex
const regex = /^((?<scheme>[^:\/?#]+):)?(\/\/(?<authority>(?<domain>[^\/?#:]*)(:(?<port>[0-9]*))?))?((?<path>[^?#]*)\\?)?((?<query>([^#]*)))?(#(?<fragment>(.*)))?/;
/* Result:
authority: ""
domain: ""
fragment: "nose"
path: "/over/there"
port: "8042"
query: "?name=ferret"
scheme: "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.