mIRC Home    About    Download    Register    News    Help

Print Thread
Filter regex problem #53701 11/10/03 02:40 PM
Joined: Dec 2002
Posts: 56
Infernal_Demon Offline OP
Babel fish
OP Offline
Babel fish
Joined: Dec 2002
Posts: 56
I am trying to filter some lines in a window:
RAW.318 !Script enigma.w2
RAW.369 !Script enigma.w2
RAW.Other <pre> <text>
RAW.306 <pre> You (<me>) are now away.

These are just a few, there are much more. The problem is I am trying to remove some of them by using filter and regex like this:

filter -cwwxg @teste @teste ^/raw.3(11|14|19|12|01|13|17|18|69)/i

This does not work, but if I do this:
filter -cwwxg @teste @teste ^RAW.3(11|14|19|12|01|13|17|18|69)

It works. Should´t the //i remove the case-sensitive thing in regex?


Re: Filter regex problem #53702 11/10/03 03:01 PM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
It does that, but for /filter you can't use /X switches :tongue:
filter -cwwxg @teste @teste /(?i)^raw.3(11|14|19|12|01|13|17|18|69)/
(?i) sets the pattern following as caseless.

Re: Filter regex problem #53703 12/10/03 10:29 AM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Actually, you can use //X switches. It's just that you used "[color:red]^/raw.3(11|14|19|12|01|13|17|18|69)/i[/color]" when it should be "/[color:red]^raw.3(11|14|19|12|01|13|17|18|69)/i[/color]", which works.


* cold edits his posts 24/7
Re: Filter regex problem #53704 12/10/03 10:44 AM
Joined: Feb 2003
Posts: 2,662
Raccoon Online
Hoopy frood
Online
Hoopy frood
Joined: Feb 2003
Posts: 2,662
Actually, you can't use //X switches in /filter or $hmatch or anything else but $regex and $regsub. I just tested this again to double check and nothing has changed. (Edit: Except perhaps for event match-text. I haven't tested that yet.)

As Iori said, you can use the PCRE flag (?i) before the string you wish to CaSe InSeNsItIvE, and optionally close with (?-i).

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: Filter regex problem #53705 12/10/03 11:01 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Actually it doesn't really work, although it appears that it tries harder than previous versions. There is an old bug (ever since regex support was implemented) in /filter which prevents you from using modifiers, because /filter seems to repeatedly stip out the quotes and modifiers (the red parts in m/<pattern>/imsxg). For example:

//window @a | tokenize 44 blah,Blah,bLAH | aline @a $* | window @b | filter -wwg @a @b /blah/i
doesn't work correctly

//window @a | tokenize 44 blah,Blah,bLAH | aline @a $* | window @b | filter -wwg @a @b /(?i)blah/
works

You can find out more about how this quote stripping is done (it's done repeatedly, like peeling an onion) with a few tests. Fex, try this:
//window @a | tokenize 44 miRCa,miRCb,pirch | aline @a $* | window @b | filter -wwg @a @b /mirc/i

The bottom line is:
a) you shouldn't use modifiers in /filter, use the internal option setting (?imsx-imsx) instead
b) you should make sure that your pattern doesn't begin with the letter "m"

Forgot about $hfind(), which does that too. It would appear that there's something wrong with PCRE, but I tend to believe it's mirc's fault in some strange way.

Last edited by qwerty; 12/10/03 11:12 AM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Filter regex problem #53706 12/10/03 11:14 AM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
That's odd, since it did work with the poster's code. Sorry anyway.


* cold edits his posts 24/7
Re: Filter regex problem #53707 12/10/03 11:17 AM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Well now I'm not sure anymore that it fully works with events, but I've used the //S strip switch before and it worked. I also tested the poster's code above and it worked too.. however, qwerty's examples didn't. So yeah, I was wrong, but I can't understand this bug..


* cold edits his posts 24/7
Re: Filter regex problem #53708 12/10/03 12:57 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.
Code:
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/) -&gt; blah
$stripquotes(m/blah/) -&gt; blah
$stripquotes(m#blah#gi) -&gt; blah
$stripquotes(/blah/i) -&gt; 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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Filter regex problem #53709 12/10/03 01:24 PM
Joined: Feb 2003
Posts: 810
C
cold Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
It does make sense now. So, /filter ignores quotes and their switches when repeating its scans. Thanks very much for the explanation, again smile


* cold edits his posts 24/7