mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
59d52cec67
commit
63ffa557ba
1 changed files with 24 additions and 1 deletions
|
@ -155,7 +155,30 @@ const maxOrValues = 100
|
||||||
// It returns plaintext pefix and the remaining regular expression
|
// It returns plaintext pefix and the remaining regular expression
|
||||||
// without capturing parens.
|
// without capturing parens.
|
||||||
func SimplifyRegex(expr string) (string, string) {
|
func SimplifyRegex(expr string) (string, string) {
|
||||||
return simplifyRegex(expr, true)
|
prefix, suffix := simplifyRegex(expr, true)
|
||||||
|
sre := mustParseRegexp(suffix)
|
||||||
|
|
||||||
|
if sre.Op == syntax.OpConcat {
|
||||||
|
subs := sre.Sub
|
||||||
|
if prefix == "" {
|
||||||
|
// Drop .* at the start
|
||||||
|
for len(subs) > 0 && isDotOp(subs[0], syntax.OpStar) {
|
||||||
|
subs = subs[1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop .* at the end.
|
||||||
|
for len(subs) > 0 && isDotOp(subs[len(subs)-1], syntax.OpStar) {
|
||||||
|
subs = subs[:len(subs)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
sre.Sub = subs
|
||||||
|
if len(subs) == 0 {
|
||||||
|
return prefix, ""
|
||||||
|
}
|
||||||
|
suffix = sre.String()
|
||||||
|
}
|
||||||
|
return prefix, suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimplifyPromRegex simplifies the given Prometheus-like expr.
|
// SimplifyPromRegex simplifies the given Prometheus-like expr.
|
||||||
|
|
Loading…
Reference in a new issue