Files
EdgeCommon/pkg/configutils/match.go

26 lines
430 B
Go
Raw Normal View History

2020-09-13 19:27:47 +08:00
package configutils
import (
"regexp"
"strings"
)
var whitespaceReg = regexp.MustCompile(`\s+`)
2023-08-08 15:12:28 +08:00
// MatchKeyword 关键词匹配
2020-09-13 19:27:47 +08:00
func MatchKeyword(source, keyword string) bool {
if len(keyword) == 0 {
return false
}
pieces := whitespaceReg.Split(keyword, -1)
source = strings.ToLower(source)
for _, piece := range pieces {
2023-08-08 15:12:28 +08:00
if strings.Contains(source, strings.ToLower(piece)) {
2020-09-13 19:27:47 +08:00
return true
}
}
return false
}