regex

package
v0.0.0-...-36ca5f9 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match struct {
	Pattern *Pattern
	// contains filtered or unexported fields
}

Match represents a (sub)match as defined by the go regexp package. It stores a pointer to the underlying regex pattern as well as the capture groups' contents

func (*Match) Capture

func (m *Match) Capture(index int) string

Capture returns an individual capture group of the given Match m in the order of their declaration in the pattern of m.Pattern. Beware that m.Capture(0) returns the entire match, so m.Capture(1) will return the first capture group of the match and so forth

func (*Match) CaptureByName

func (m *Match) CaptureByName(name string) string

CaptureByName will return the capture group of the given Match m with the identifier name as specified in the pattern m.Pattern. This method will panic if name is not a valid name of any capture group of m.Pattern

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern represents a regex-pattern similar to regexp.Regexp and essentially works in the same way.

func MustCompile

func MustCompile(pattern string, names ...string) Pattern

MustCompile returns a new Pattern p with an underlying *regexp.Regexp that is created as specified by regexp.MustCompile(..). This method allows for appending the names of the capture groups after pattern. To refer to a capture group name in the pattern use %s as specified by e.g. fmt.Sprintf(..)

func (*Pattern) FindStringSubmatch

func (p *Pattern) FindStringSubmatch(s string) (Match, error)

FindStringSubmatch works like *regexp.Regexp.FindStringSubmatch(...) but returns an error if s can't be matched against the pattern p

func (*Pattern) Regex

func (p *Pattern) Regex() *regexp.Regexp

Regex returns the underlying *regexp.Regexp of p. The return value should NOT be modified as it changes in p respectively.

Jump to

Keyboard shortcuts

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