regexutil

package
v1.93.10 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: Apache-2.0 Imports: 6 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOrValues

func GetOrValues(expr string) []string

GetOrValues returns "or" values from the given regexp expr.

It ignores start and end anchors ('^') and ('$') at the start and the end of expr. It returns ["foo", "bar"] for "foo|bar" regexp. It returns ["foo"] for "foo" regexp. It returns [""] for "" regexp. It returns an empty list if it is impossible to extract "or" values from the regexp.

func RemoveStartEndAnchors

func RemoveStartEndAnchors(expr string) string

RemoveStartEndAnchors removes '^' at the start of expr and '$' at the end of the expr.

func Simplify

func Simplify(expr string) (string, string)

Simplify simplifies the given expr.

It returns plaintext prefix and the remaining regular expression with dropped '^' and '$' anchors at the beginning and the end of the regular expression.

The function removes capturing parens from the expr, so it cannot be used when capturing parens are necessary.

Types

type PromRegex

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

PromRegex implements an optimized string matching for Prometheus-like regex.

The following regexs are optimized:

- plain string such as "foobar" - alternate strings such as "foo|bar|baz" - prefix match such as "foo.*" or "foo.+" - substring match such as ".*foo.*" or ".+bar.+"

The rest of regexps are also optimized by returning cached match results for the same input strings.

func NewPromRegex

func NewPromRegex(expr string) (*PromRegex, error)

NewPromRegex returns PromRegex for the given expr.

func (*PromRegex) MatchString

func (pr *PromRegex) MatchString(s string) bool

MatchString returns true if s matches pr.

The pr is automatically anchored to the beginning and to the end of the matching string with '^' and '$'.

Jump to

Keyboard shortcuts

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