diff --git a/model/labels/matcher_test.go b/model/labels/matcher_test.go index 14615a50d..6a95358f7 100644 --- a/model/labels/matcher_test.go +++ b/model/labels/matcher_test.go @@ -81,6 +81,21 @@ func TestMatcher(t *testing.T) { value: "foo-bar", match: false, }, + { + matcher: mustNewMatcher(t, MatchRegexp, "$*bar"), + value: "foo-bar", + match: false, + }, + { + matcher: mustNewMatcher(t, MatchRegexp, "bar^+"), + value: "foo-bar", + match: false, + }, + { + matcher: mustNewMatcher(t, MatchRegexp, "$+bar"), + value: "foo-bar", + match: false, + }, } for _, test := range tests { diff --git a/model/labels/regexp.go b/model/labels/regexp.go index 6406b5d9b..5c9d033ba 100644 --- a/model/labels/regexp.go +++ b/model/labels/regexp.go @@ -163,6 +163,9 @@ func clearBeginEndText(re *syntax.Regexp) { } if len(re.Sub) == 1 { if re.Sub[0].Op == syntax.OpBeginText || re.Sub[0].Op == syntax.OpEndText { + // We need to remove this element. Since it's the only one, we convert into a matcher of an empty string. + // OpEmptyMatch is regexp's nop operator. + re.Op = syntax.OpEmptyMatch re.Sub = nil return }