Created
December 6, 2018 16:37
-
-
Save asika32764/cf1803c08450dfcc80d192571ffd1e1f to your computer and use it in GitHub Desktop.
Javascript URL parsing regex
This file contains hidden or 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
| const regex = /^((?<scheme>[^:\/?#]+):)?(\/\/(?<authority>(?<domain>[^\/?#:]*)(:(?<port>[0-9]*))?))?((?<path>[^?#]*)\\?)?((?<query>([^#]*)))?(#(?<fragment>(.*)))?/; | |
| 'foo://example.com:8042/over/there?name=ferret#nose'.match(regex); | |
| /* Result: | |
| authority: "example.com:8042" | |
| domain: "example.com" | |
| 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