The reason that it works sometimes is that mirc takes into account the /i just before it strips out the quotes (and any modifier that follows them). When /filter scans the file/window lines for a match, it strips anything that considers quotes with each repetition. I'll try to simulate mirc's behaviour when you call /filter -g with a mirc script.
alias fil {
close -@ @source @dest
window @source | window @dest
var %i = 1, %pattern = $1-
tokenize 44 miRCa,miRCb,pirch
aline @source $*
while $line(@source,%i) {
%line = $ifmatch
echo 3 -s Pattern is %pattern
if $regex(%line,%pattern) { aline @dest %line }
%pattern = $stripquotes(%pattern)
inc %i
}
}
/*
$stripquotes(/blah/) -> blah
$stripquotes(m/blah/) -> blah
$stripquotes(m#blah#gi) -> blah
$stripquotes(/blah/i) -> blah
*/
alias stripquotes {
var %a
!.echo -q $regsub($1,/m(.)(.+)\1.*|(/)(.+)/.*/,\2,%a)
return %a
}
alias fil2 {
close -@ @source @dest
window @source | window @dest
var %i = 1, %pattern = $1-
tokenize 44 miRCa,miRCb,pirch
aline @source $*
filter -wwg @source @dest %pattern
}
Type /fil <pattern-you-want> and observe the output in @dest for various input patterns. Try these, one after another:
/fil /m#rc#i/
/fil /m#rc#i/i
/fil /m#rc#/i
/fil /m#rC#i/i
/fil /m#rC#/i
Then you can try the same inputs with /fil2 (which calls the real /filter -g), you'll notice that the results are the same.
As you can see, the above code loops through the @source lines and checks each line against the pattern you gave it, but after that, it strips the quotes from the pattern. So, in the next repetition, the next line is checked against the stripped pattern, and this repeated stripping goes on until the last line.
The $stripquotes() alias simulates the actual bug. There is no such thing in mirc's source code of course, but the result of the bug is the same as this hypothetical function.
I hope it made some sense now.