regex

package
v2.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package regex wraps the Golang regexp package to provide more convenient access to some features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Groups

func Groups(r *regexp.Regexp, token string) []string

Convenience function for getting groups from a regex match Returns nil if no match is made, otherwise returns the groups that were matched via regexp.FindAllStringsSubmatch

Types

type Pattern

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

Patterns are a combination of static string components and regex validation. Any piece of the string contained in brackets {} will be matched as regex, while any outside of brackets will be matched as itself; for example, {.*}.jnichols.{.*} matches any subdomain and top-level domain for jnichols. Patterns *must* contain some regex. It performs generally equivalent to the exact same regex in brackets (see regex_bench_test.go) and better if static string parts are swapped out of the expression entirely.

func CompilePattern

func CompilePattern(expr string) (*Pattern, error)

CompilePattern compiles a string pattern expression to a *regex.Pattern.

Returns patt, isPatt, err, where err != nil if the pattern is invalid and !isPatt if the provided expression is valid, but not a pattern (a static string).

func (*Pattern) Match

func (patt *Pattern) Match(str string) bool

Match matches a pattern to a string.

Jump to

Keyboard shortcuts

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