diff --git a/pkg/labels/matcher.go b/pkg/labels/matcher.go index 40ae5f76e..7fa5d947e 100644 --- a/pkg/labels/matcher.go +++ b/pkg/labels/matcher.go @@ -59,8 +59,7 @@ func NewMatcher(t MatchType, n, v string) (*Matcher, error) { Value: v, } if t == MatchRegexp || t == MatchNotRegexp { - m.Value = "^(?:" + v + ")$" - re, err := regexp.Compile(m.Value) + re, err := regexp.Compile("^(?:" + v + ")$") if err != nil { return nil, err } diff --git a/storage/tsdb/tsdb.go b/storage/tsdb/tsdb.go index 966dfd55e..33572c93f 100644 --- a/storage/tsdb/tsdb.go +++ b/storage/tsdb/tsdb.go @@ -233,14 +233,14 @@ func convertMatcher(m *labels.Matcher) tsdbLabels.Matcher { return tsdbLabels.Not(tsdbLabels.NewEqualMatcher(m.Name, m.Value)) case labels.MatchRegexp: - res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value) + res, err := tsdbLabels.NewRegexpMatcher(m.Name, "^(?:"+m.Value+")$") if err != nil { panic(err) } return res case labels.MatchNotRegexp: - res, err := tsdbLabels.NewRegexpMatcher(m.Name, m.Value) + res, err := tsdbLabels.NewRegexpMatcher(m.Name, "^(?:"+m.Value+")$") if err != nil { panic(err) }