func TestMatch(t *testing.T) { re := regexp.MustCompile(`test`) if !re.Match([]byte(`test string`)) { t.Error(`not match`) } if re.ReplaceAll([]byte(`test_string`), []byte(`changed`)) != "changed_string" { t.Error(`not match`) } }
func (rule *Rule) urlMatches(u string) bool { if rule.regex == nil { rule.regex = regexp.MustCompile(rule.regexString) } return rule.regex.MatchString(u) }
"document", "elemhide", "other", "background", "xbl", "ping", "dtd", "media", "third-party", "match-case", "collapse", "donottrack", "popup", } optionsSplitPat = fmt.Sprintf(",(?=~?(?:%v))", strings.Join(append(binaryOptions, "doman"), "|")) optionsSplitRe = regexp.MustCompile(optionsSplitPat) escapeSpecialRegxp = re.MustCompile(`([.$+?{}()\[\]\\])`) ) func createCheckStringSetFunc(checkFunc func(string, string) bool) func(string, ...string) bool { return func(s string, sets ...string) bool { for _, set := range sets { if checkFunc(s, set) { return true } } return false } }