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.

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


parse_url https://visionsystemsinc.github.io:443/vsi_common/just/quickstart_user.html?highlight=J.U.S.T#what-is-j-u-s-t

Output:

parsed_url_scheme - e.g., https parsed_url_authority - e.g., visionsystemsinc.github.io:443 parsed_url_host - e.g., visionsystemsinc.github.io parsed_url_port - e.g., 443 parsed_url_rpath - e.g., vsi_common/just/quickstart_user.html parsed_url_query - e.g., highlight=J.U.S.T parsed_url_fragment - e.g., what-is-j-u-s-t