regexutil

package
v1.0.0-victorialogs Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOrValuesPromRegex added in v1.97.7

func GetOrValuesPromRegex(expr string) []string

GetOrValuesPromRegex returns "or" values from the given Prometheus-like 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 GetOrValuesRegex added in v1.97.7

func GetOrValuesRegex(expr string) []string

GetOrValuesRegex returns "or" values from the given regexp 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 SimplifyPromRegex added in v1.97.7

func SimplifyPromRegex(expr string) (string, string)

SimplifyPromRegex simplifies the given Prometheus-like expr.

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

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

func SimplifyRegex added in v1.97.7

func SimplifyRegex(expr string) (string, string)

SimplifyRegex simplifies the given regexp expr.

It returns plaintext pefix and the remaining regular expression without capturing parens.

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 '$'.

func (*PromRegex) String added in v1.97.7

func (pr *PromRegex) String() string

String returns string representation of pr.

type Regex added in v1.97.7

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

Regex implements an optimized string matching for Go 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.+"

func NewRegex added in v1.97.7

func NewRegex(expr string) (*Regex, error)

NewRegex returns Regex for the given expr.

func (*Regex) GetLiterals added in v1.97.7

func (r *Regex) GetLiterals() []string

GetLiterals returns literals for r.

func (*Regex) MatchString added in v1.97.7

func (r *Regex) MatchString(s string) bool

MatchString returns true if s matches r.

func (*Regex) String added in v1.97.7

func (r *Regex) String() string

String returns string represetnation for r

Jump to

Keyboard shortcuts

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