diff --git a/internal/base/SerializableHelpers.go b/internal/base/SerializableHelpers.go index 664b2ed..b43e302 100644 --- a/internal/base/SerializableHelpers.go +++ b/internal/base/SerializableHelpers.go @@ -19,7 +19,11 @@ func NewRegexp(pattern string) Regexp { } func (x Regexp) Valid() bool { return x.Regexp != nil } func (x *Regexp) Set(in string) (err error) { - x.Regexp, err = regexp.Compile(in) + if len(in) > 0 { + x.Regexp, err = regexp.Compile(in) + } else { + x.Regexp = nil + } return } func (x Regexp) String() string { diff --git a/utils/UFS.go b/utils/UFS.go index 01819f4..8b03ad6 100644 --- a/utils/UFS.go +++ b/utils/UFS.go @@ -1105,8 +1105,13 @@ func MakeGlobRegexpExpr(glob ...string) string { if len(glob) == 0 { return ".*" } + var expr strings.Builder - expr.WriteString("(?i)(?:") // insensitive, non-capturing group + expr.WriteString("(?i)") // insensitive + if len(glob) > 1 { // non-capturing group + expr.WriteString("(?:") + } + for i, it := range glob { it = regexp.QuoteMeta(it) it = strings.ReplaceAll(it, "\\?", ".") @@ -1121,7 +1126,10 @@ func MakeGlobRegexpExpr(glob ...string) string { expr.WriteString(it) expr.WriteRune(')') } - expr.WriteString(")") + + if len(glob) > 1 { // non-capturing group + expr.WriteRune(')') + } return expr.String() } func MakeGlobRegexp(glob ...string) base.Regexp {