goodregex

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 1 Imported by: 2

README

CI

A collection of regular expressions for Go. This is the core of resolveip.

The name does not make any claims about the quality of the regular expressions included. The author just needed a short intuitive name :-)

Feedback, tests and comments are always welcome.

Installation

go get github.com/hreese/goodregex

Usage

Go Reference

This package currently exports three regular expressions:

  • MatchIPv4 (matches IPv4 addresses)
  • MatchIPv6 (matches IPv6 addresses)
  • MatchHostname (matches hostnames)

Experimental bounded versions (MatchBoundedIPv4, MatchBoundedHostname) are also available. These only match when the pattern is surrounded by word boundaries, preventing partial matches inside longer strings.

Use them like normal regular expressions from regexp.

This package also exports CompileReadableRegex and MustCompileReadableRegex, which compile "readable regexes" -- RE2 expressions with embedded whitespace and #-style comments stripped before compilation.

Documentation

Overview

Package goodregex provides a collection of pre-compiled regular expressions for matching IPv4 addresses, IPv6 addresses, and hostnames.

It also provides CompileReadableRegex and MustCompileReadableRegex, which accept "readable regexes" -- regular RE2 expressions with embedded whitespace and comments for human readability.

Index

Constants

This section is empty.

Variables

View Source
var MatchBoundedHostname = MustCompileReadableRegex(`(?:\b` + regexMatchHostname + `\b)`)

MatchBoundedHostname is an experimental version of MatchHostname that only matches if the hostname is surrounded by a word border.

View Source
var MatchBoundedIPv4 = MustCompileReadableRegex(`(?:\b` + regexMatchV4 + `\b)`)

MatchBoundedIPv4 is an experimental version of MatchIPv4 that only matches if the IPv4 address is surrounded by a word border.

View Source
var MatchHostname = MustCompileReadableRegex(regexMatchHostname)

MatchHostname matches a hostname according to RfC 1123 2.1

View Source
var MatchIPv4 = MustCompileReadableRegex(regexMatchV4)

MatchIPv4 matches IPv4 addresses in dotted decimal notation

View Source
var MatchIPv6 = MustCompileReadableRegex(regexMatchV6)

MatchIPv6 matches IPv6 addresses. It supports colon-separated hexadecimal notation including ::-abbreviation, IPv4-embedded IPv6 addresses and IPv4-Mapped IPv6 Address. The unspecified address "::" is not matched as it cannot be resolved or connected to.

Functions

func CompileReadableRegex

func CompileReadableRegex(r string) (*regexp.Regexp, error)

CompileReadableRegex is similar to regexp.Compile. It accepts a "readable regex" which is a regular RE2 regexp where whitespace and comments (a # followed by everything until the end of line) are removed prior to compilation.

func MustCompileReadableRegex

func MustCompileReadableRegex(r string) *regexp.Regexp

MustCompileReadableRegex is similar to regexp.MustCompile. It accepts a "readable regex" which is a regular RE2 regexp where whitespace and comments (a # followed by everything until the end of line) are removed prior to compilation. It panics if the expression cannot be parsed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL