Parser
- parser.bsh
Functions to parse and/or validate common strings like URLs, etc.
- PARSER_URI_REGEX
A (best-effort) regex to parse a URL
The following regex is based on https://tools.ietf.org/html/rfc3986#appendix-B with additional sub-expressions to split authority into userinfo, host and port
Warning
Parsing URLs 100% correctly is HARD. This is not that solution.
Note
- parse_url
Parse a URL
Parse a URL into its various parts: scheme, authority, user, host, port, rpath, query, fragment. Parsing URLs 100% correctly is HARD. This is not that solution.
- Arguments:
$1
- URL
Example
- Output:
parsed_url_scheme
- e.g., httpsparsed_url_authority
- e.g., visionsystemsinc.github.io:443parsed_url_host
- e.g., visionsystemsinc.github.ioparsed_url_port
- e.g., 443parsed_url_rpath
- e.g., vsi_common/just/quickstart_user.htmlparsed_url_query
- e.g., highlight=J.U.S.Tparsed_url_fragment
- e.g., what-is-j-u-s-t