# URI::REGEXP::PATTERN (Module)

In: | uri/common.rb

## Constants

ALPHA | = | "a-zA-Z"
| alpha = lowalpha | upalpha
ALNUM | = | "#{ALPHA}\\d"
| alphanum = alpha | digit
HEX | = | "a-fA-F\\d"
| hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
                            "a" | "b" | "c" | "d" | "e" | "f"
ESCAPED | = | "%[#{HEX}]{2}"
| escaped = "%" hex hex
UNRESERVED | = | "-_.!~*'()#{ALNUM}"
| mark = "-" | "_" | "." | "!" | "~" | "*" | "’" |
                    "(" | ")"
unreserved = alphanum | mark
RESERVED | = | ";/?:@&=+$,\\[\\]"
| reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | "," | "[" | "]" (RFC 2732)
URIC | = | "(?:[#{UNRESERVED}#{RESERVED}]|#{ESCAPED})"
| uric = reserved | unreserved | escaped
URIC_NO_SLASH | = | "(?:[#{UNRESERVED};?:@&=+$,]|#{ESCAPED})"
| uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
                    "&" | "=" | "+" | "$" | ","
QUERY | = | "#{URIC}*"
| query = *uric
FRAGMENT | = | "#{URIC}*"
| fragment = *uric
DOMLABEL | = | "(?:[#{ALNUM}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
| domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
TOPLABEL | = | "(?:[#{ALPHA}](?:[-#{ALNUM}]*[#{ALNUM}])?)"
| toplabel = alpha | alpha *( alphanum | "-" ) alphanum
HOSTNAME | = | "(?:#{DOMLABEL}\\.)*#{TOPLABEL}\\.?"
| hostname = *( domainlabel "." ) toplabel [ "." ]
IPV4ADDR | = | "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"
| RFC 2373, APPENDIX B: IPv6address = hexpart [ ":" IPv4address ] IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ] hexseq = hex4 *( ":" hex4) hex4 = 1*4HEXDIG XXX: This definition has a flaw. "::" + IPv4address must be allowed too. Here is a replacement. IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
HEX4 | = | "[#{HEX}]{1,4}"
| hex4 = 1*4HEXDIG
LASTPART | = | "(?:#{HEX4}|#{IPV4ADDR})"
| lastpart = hex4 | IPv4address
HEXSEQ1 | = | "(?:#{HEX4}:)*#{HEX4}"
| hexseq1 = *( hex4 ":" ) hex4
HEXSEQ2 | = | "(?:#{HEX4}:)*#{LASTPART}"
| hexseq2 = *( hex4 ":" ) lastpart
IPV6ADDR | = | "(?:#{HEXSEQ2}|(?:#{HEXSEQ1})?::(?:#{HEXSEQ2})?)"
| IPv6address = hexseq2 | [ hexseq1 ] "::" [ hexseq2 ]
IPV6REF | = | "\\[#{IPV6ADDR}\\]"
| ipv6reference = "[" IPv6address "]" (RFC 2732)
HOST | = | "(?:#{HOSTNAME}|#{IPV4ADDR}|#{IPV6REF})"
| host = hostname | IPv4address host = hostname | IPv4address | IPv6reference (RFC 2732)
PORT | = | "\d*"
| port = *digit
HOSTPORT | = | "#{HOST}(?:#{PORT})?"
| hostport = host [ ":" port ]
USERINFO | = | "(?:[#{UNRESERVED};:&=+$,]|#{ESCAPED})*"
| userinfo = *( unreserved | escaped |
                       ";" | ":" | "&" | "=" | "+" | "$" | "," )
PCHAR | = | "(?:[#{UNRESERVED}:@&=+$,]|#{ESCAPED})"
| pchar = unreserved | escaped |
                    ":" | "@" | "&" | "=" | "+" | "$" | ","
PARAM | = | "#{PCHAR}*"
| param = *pchar
SEGMENT | = | "#{PCHAR}*(?:;#{PARAM})*"
| segment = *pchar *( ";" param )
PATH_SEGMENTS | = | "#{SEGMENT}(?:/#{SEGMENT})*"
| path_segments = segment *( "/" segment )
SERVER | = | "(?:#{USERINFO}@)?#{HOSTPORT}"
| server = [ [ userinfo "@" ] hostport ]
REG_NAME | = | "(?:[#{UNRESERVED}$,;+@&=+]|#{ESCAPED})+"
| reg_name = 1*( unreserved | escaped | "$" | "," |
                        ";" | ":" | "@" | "&" | "=" | "+" )
AUTHORITY | = | "(?:#{SERVER}|#{REG_NAME})"
| authority = server | reg_name
REL_SEGMENT | = | "(?:[#{UNRESERVED};@&=+$,]|#{ESCAPED})+"
| rel_segment = 1*( unreserved | escaped |
                        ";" | "@" | "&" | "=" | "+" | "$" | "," )
SCHEME | = | "[#{ALPHA}][-+.#{ALPHA}\\d]*"
| scheme = alpha *( alpha | digit | "+" | "-" | "." )
ABS_PATH | = | "/#{PATH_SEGMENTS}"
| abs_path = "/" path_segments
REL_PATH | = | "#{REL_SEGMENT}(?:#{ABS_PATH})?"
| rel_path = rel_segment [ abs_path ]
NET_PATH | = | "//#{AUTHORITY}(?:#{ABS_PATH})?"
| net_path = "//" authority [ abs_path ]
HIER_PART | = | "(?:#{NET_PATH}|#{ABS_PATH})(?:\\?(?:#{QUERY}))?"
| hier_part = ( net_path | abs_path ) [ "?" query ]
OPAQUE_PART | = | "#{URIC_NO_SLASH}#{URIC}*"
| opaque_part = uric_no_slash *uric
ABS_URI | = | "#{SCHEME}:(?:#{HIER_PART}|#{OPAQUE_PART})"
| absoluteURI = scheme ":" ( hier_part | opaque_part )
REL_URI | = | "(?:#{NET_PATH}|#{ABS_PATH}|#{REL_PATH})(?:\\?#{QUERY})?"
| relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
URI_REF | = | "(?:#{ABS_URI}|#{REL_URI})?(?:##{FRAGMENT})?"
| URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
X_ABS_URI | = | " (#{PATTERN::SCHEME}): (?# 1: scheme) (?: (#{PATTERN::OPAQUE_PART}) (?# 2: opaque) | (?:(?: //(?: (?:(?:(#{PATTERN::USERINFO})@)? (?# 3: userinfo) (?:(#{PATTERN::HOST})(?::(\\d*))?))?(?# 4: host, 5: port) | (#{PATTERN::REG_NAME}) (?# 6: registry) ) | (?!//)) (?# XXX: '//' is the mark for hostport) (#{PATTERN::ABS_PATH})? (?# 7: path) )(?:\\?(#{PATTERN::QUERY}))? (?# 8: query) ) (?:\\#(#{PATTERN::FRAGMENT}))? (?# 9: fragment) "
| XXX:
X_REL_URI | = | " (?: (?: // (?: (?:(#{PATTERN::USERINFO})@)? (?# 1: userinfo) (#{PATTERN::HOST})?(?::(\\d*))? (?# 2: host, 3: port) | (#{PATTERN::REG_NAME}) (?# 4: registry) ) ) | (#{PATTERN::REL_SEGMENT}) (?# 5: rel_segment) )? (#{PATTERN::ABS_PATH})? (?# 6: abs_path) (?:\\?(#{PATTERN::QUERY}))? (?# 7: query) (?:\\#(#{PATTERN::FRAGMENT}))? (?# 8: fragment) "

[Validate]