diff --git a/collections/slice.go b/collections/slice.go index a5cd3d9..2d44a76 100644 --- a/collections/slice.go +++ b/collections/slice.go @@ -120,6 +120,12 @@ func matchPattern(item, pattern string) bool { return true } + if strings.HasPrefix(pattern, "*") && strings.HasSuffix(pattern, "*") { + if strings.Contains(item, strings.TrimPrefix(strings.TrimSuffix(pattern, "*"), "*")) { + return true + } + } + if strings.HasPrefix(pattern, "*") { if strings.HasSuffix(item, strings.TrimPrefix(pattern, "*")) { return true diff --git a/collections/slice_test.go b/collections/slice_test.go index b8a75b6..31bc582 100644 --- a/collections/slice_test.go +++ b/collections/slice_test.go @@ -63,9 +63,15 @@ func TestMatchItems(t *testing.T) { { name: "Multiple Wildcards", item: "apple", - patterns: []string{"ap*e", "*p*"}, + patterns: []string{"ap*e", "*pl*e"}, expected: false, }, + { + name: "Glob", + item: "apple", + patterns: []string{"*ppl*"}, + expected: true, + }, { name: "Handle whitespaces | should be trimmed", item: "hello",