From: martin f. krafft Date: Thu, 9 Sep 2021 23:27:37 +0000 (+0200) Subject: Improved wildcard matching X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=1bda6cd6adf4b012d4156c89dcb3eaf6a15169f4;p=irssi-scripts.irssi.org.git Improved wildcard matching No reason why '*' cannot appear as part of a word, e.g. 'debian-*', so let's implement that. Signed-off-by: martin f. krafft --- diff --git a/scripts/ctrlact.pl b/scripts/ctrlact.pl index 74464f2..19b6c23 100644 --- a/scripts/ctrlact.pl +++ b/scripts/ctrlact.pl @@ -46,8 +46,8 @@ # # Note that the name is either matched in full and verbatim, or treated like # a regular expression, if it starts and ends with the same punctuation -# character. The asterisk ('*') is special and simply gets translated to /.*/ -# internally. No other wildcards are supported. +# character. You may also use the asterisk by itself to match everything, or +# as part of a word, e.g. #debian-*. No other wildcards are supported. # # Once you defined your mappings, please don't forget to /ctrlact reload them. # You can then use the following commands from Irssi to check out the result: @@ -207,14 +207,15 @@ my @query_thresholds; sub match { my ($pat, $text) = @_; - my $npat = ($pat eq '*') ? '/.*/' : $pat; - if ($npat =~ m/^(\W)(.+)\1$/) { - my $re = qr/$2/; - $pat = $2 unless $pat eq '*'; - return $pat if $text =~ /$re/i; + if ($pat =~ m/^(\W)(.+)\1$/) { + return $pat if $text =~ /$2/i; + } + elsif ($pat =~ m/\*/) { + my $rpat = $pat =~ s/\*/.*/gr; + return $pat if $text =~ /$rpat/ } else { - return $pat if lc($text) eq lc($npat); + return $pat if lc($text) eq lc($pat); } return 0; }