Module: HostnameRegexes
- Included in:
- TopinambourRegex
- Defined in:
- lib/terminal_regex.rb
Constant Summary collapse
- HOSTNAMESEGMENTCHARS_CLASS =
Either an alphanumeric character or dash; or if [negative lookahead] not ASCII then any graphical Unicode character. A segment can consist entirely of numbers. (Note: PCRE doesn’t support character class subtraction/intersection.) */
"(?x: [-[:alnum:]] | (?! [[:ascii:]] ) [[:graph:]] )"
- HOSTNAME1 =
A hostname of at least 1 component. The last component cannot be entirely numbers. E.g. “foo”, “example.com”, “1234.com”, but not “foo.123” */
"(?x: (?: #{HOSTNAMESEGMENTCHARS_CLASS}+ \\. )* " + "#{HOSTNAMESEGMENTCHARS_CLASS}* (?! [0-9] ) #{HOSTNAMESEGMENTCHARS_CLASS}+ )"
- HOSTNAME2 =
A hostname of at least 2 components. The last component cannot be entirely numbers. E.g. “example.com”, “1234.com”, but not “1234.56” */
"(?x: (?: #{HOSTNAMESEGMENTCHARS_CLASS}+ \\.)+ #{HOSTNAME1} )"
- URL_HOST =
For URL: Hostname, IPv4, or bracket-enclosed IPv6, e.g. “example.com”, “1.2.3.4”, “[::1]” */
"(?x: #{HOSTNAME1} | (?&IPV4) | \\[ (?&IPV6) \\] )"
- EMAIL_HOST =
For e-mail: Hostname of at least two segments, or bracket-enclosed IPv4 or IPv6, e.g. “example.com”, “[1.2.3.4]”, “[::1]”. Technically an e-mail with a single-component hostname might be valid on a local network, but let’s avoid tons of false positives (e.g. in a typical shell prompt). */
"(?x: #{HOSTNAME2} | \\[ (?: (?&IPV4) | (?&IPV6) ) \\] )"