Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOrValuesPromRegex ¶ added in v1.97.7
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
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 ¶
RemoveStartEndAnchors removes '^' at the start of expr and '$' at the end of the expr.
func SimplifyPromRegex ¶ added in v1.97.7
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
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 ¶
NewPromRegex returns PromRegex for the given expr.
func (*PromRegex) MatchString ¶
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 '$'.
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 (*Regex) GetLiterals ¶ added in v1.97.7
GetLiterals returns literals for r.
func (*Regex) MatchString ¶ added in v1.97.7
MatchString returns true if s matches r.