Last active
May 12, 2022 06:17
-
-
Save therightstuff/bc2ff4dcf73a9809b01e056d85828bb3 to your computer and use it in GitHub Desktop.
Reading and writing regular expressions for sane people
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
var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})(0–9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/; | |
... |
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
// parse a url, only capture the host part | |
// eg. protocol://host | |
// protocol://host:port/path?querystring#anchor | |
// host | |
// host/path | |
// host:port/path | |
// protocol://host:port/path?querystring#anchor | |
var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})(0–9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/; | |
... |
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
// parse a url, only capture the host part | |
// (?:([A-Za-z]+):)? | |
// protocol — an optional alphabetic protocol followed by a colon | |
// (\/{0,3})(0–9.\-A-Za-z]+) | |
// host — 0–3 forward slashes followed by alphanumeric characters | |
// (?::(\d+))? | |
// port — an optional colon and a sequence of digits | |
// (?:\/([^?#]*))? | |
// path — an optional forward slash followed by any number of | |
// characters not including ? or # | |
// (?:\?([^#]*))? | |
// query string — an optional ? followed by any number of | |
// characters not including # | |
// (?:#(.*))? | |
// anchor — an optional # followed by any number of characters | |
var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})(0–9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment