From 6566dd66f0b55667915cdce8d53e18f50c1e7284 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Wed, 22 Jan 2025 10:48:06 +0100 Subject: [PATCH] fixed pattern regex, fixed pattern AND operation --- cfg/config.go | 2 +- lib/filter.go | 14 +++++++++----- tablizer.1 | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index 93376a7..fbb9917 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -340,7 +340,7 @@ func (conf *Config) ApplyDefaults() { func (conf *Config) PreparePattern(patterns []*Pattern) error { // regex checks if a pattern looks like /$pattern/[i!] - flagre := regexp.MustCompile(`^/(.*)/([i!]+)$`) + flagre := regexp.MustCompile(`^/(.*)/([i!]*)$`) for _, pattern := range patterns { matches := flagre.FindAllStringSubmatch(pattern.Pattern, -1) diff --git a/lib/filter.go b/lib/filter.go index 816732d..8227e23 100644 --- a/lib/filter.go +++ b/lib/filter.go @@ -47,8 +47,9 @@ func matchPattern(conf cfg.Config, line string) bool { return fuzzy.MatchFold(conf.Patterns[0].Pattern, line) } - var match bool + var match int + //fmt.Printf("<%s>\n", line) for _, re := range conf.Patterns { patmatch := re.PatternRe.MatchString(line) if re.Negate { @@ -56,13 +57,16 @@ func matchPattern(conf cfg.Config, line string) bool { patmatch = !patmatch } - if match != patmatch { - // toggles match if the last match and current match are different - match = !match + if patmatch { + match++ } + + //fmt.Printf("patmatch: %t, match: %d, pattern: %s, negate: %t\n", patmatch, match, re.Pattern, re.Negate) } - return match + // fmt.Printf("result: %t\n", match == len(conf.Patterns)) + //fmt.Println() + return match == len(conf.Patterns) } /* diff --git a/tablizer.1 b/tablizer.1 index aa74953..d4d21ec 100644 --- a/tablizer.1 +++ b/tablizer.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TABLIZER 1" -.TH TABLIZER 1 "2025-01-21" "1" "User Commands" +.TH TABLIZER 1 "2025-01-22" "1" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l