mIRC Homepage
Posted By: elroyK /filter - 24/06/03 09:11 PM
I'm trying to filter a file to a @window, but i am kinda lost.
I want to filter it based on text in a variable, and other text in a dialog editbox. However, it should be AND/OR .. like this.
filter file.txt @window *Var*dialogeditbox*AND/OR*dialogeditbox
and preferable not in any specific order.
i could ofcourse filter first matching the first editbox, and then the second editbox, but what if a line contains both ? then i'll have the line twice in the result window..
Does anyone have any idea?
Posted By: Raccoon Re: /filter - 24/06/03 09:28 PM
Judging from your example, the inclusion of %var is redundant as it requires 'dialogeditbox' regardless... with or without %var.

However, you can still do this with a regular expressoin in /filter, which allows 'alternation' (OR) in the pattern.
/filter -fwg file.txt @window /(?: $+ %var $+ .* $+ $did(dialog,10,1).text $+ )|(?: $+ $did(dialog,10,1).text $+ )/

I'd also like to know if this works, but I'm too lazy to try it. using the /x switch, to make $+'s unnecessary.
/filter -fwg file.txt @window /(?x)(?: %var .* $did(dialog,10,1).text )|(?: $did(dialog,10,1).text )/

Of corse, this pattern would be more logical, as simply...
/filter -fwg file.txt @window /(?x)(?: %var )?.* $did(dialog,10,1).text /

- Raccoon
Posted By: elroyK Re: /filter - 24/06/03 09:49 PM
I've played around with reg exp, but they're case sensitive.. And that's useless in my case, cause what i'd be filtering is nicknames, so you never know how someone typed it.

I guess my first post was a bit confusing. What i mean is, i have two editboxes which can contain search words, and a variable. The filter should match a line if it contains the variable, and one or both of the editbox texts.
Posted By: lammkott Re: /filter - 24/06/03 11:21 PM
Try use /filter -afw that's what I've used on a couple of occassions and it seems to sort the contents fine.
Posted By: BlackAle Re: /filter - 24/06/03 11:29 PM
using /i at the end or (?i) within a regex will make it case insensitive.

OR is implemented in a regex by using the pipemark | i.e

/(this|that|whatever)/ ...would match this OR that OR whatever

for AND use..

/(?=.*this)(?=.*that)(?=.*whatever)/

and NOT can be done with...

/^(?!.*dontmatch)/


Posted By: elroyK Re: /filter - 25/06/03 12:48 AM
/i doesn't seem to work in mirc. Also, how would i put that all in a single reg exp? i've just looked over some sites for a quick introduction to it, but i don't quite grasp it yet..
What i'm looking for is something that combines %variable && (A|B) , case insensitive.
Posted By: qwerty Re: /filter - 25/06/03 12:58 AM
/i works in $regex/$regsub but not in /filter. Use (?i) for that. Don't worry if you don't get it at first, regex needs some time but after you get used to it you'll love it. The most appropriate document on mirc regex is the PCRE manual. It often gets technical but you can skip the parts that you don't understand. There's a very basic regex tutorial on www.mircscripts.org, you might want to check it out as well.
Posted By: elroyK Re: /filter - 25/06/03 01:22 AM
Here's what i cooked up so far as expression:
/(?=.*WORD)(?=.*(WORD+|WORD+))
If i'm correct, that should match on first word, plus either of the other two. I tried in my script having the output go to a custom window and it works, except for being case sensitive, I tried with a /i behind it but that doesn't make a difference. Any corrections or help ?

edit: I posted before your reply, sorry but as you see i was busy trying reg exp and testing it. Where would i put that (?i) then in my expression ?
Posted By: Raccoon Re: /filter - 25/06/03 06:39 AM
And even though the PCRE manual may be the most technically correct (because mIRC uses a PCRE implimentation), the PerlRE document is still the most comprehensive and easy to read, and over 99.9% accurate anyhow.

You'll be hard pressed to find something that doesn't work, and when you do it's usually an obvious feature that simply can't exist outside of Perl.

- Raccoon
Posted By: elroyK Re: /filter - 25/06/03 08:35 AM
It works. Only problem i got left is, it won't match if the second search word is empty, $null.. like so
/(?=.*WORD)(?i)(?=.*(WORD+|+))/
What would i do to match the first two words regardless of the third word missing ?
Posted By: elroyK Re: /filter - 25/06/03 12:13 PM
Ok i got it working with including an $iif to only put the second search word if it's actually there. thanks for the help.
Posted By: BlackAle Re: /filter - 25/06/03 12:37 PM
If you're looking to match 2 words in a particular order you don't need to use assertions, i.e (?=WORD)

/(?i)(hello).*?(world|$)/

will match 'hello' or 'hello world', but not 'world' or 'world hello'

/(?i)(?=.*(hello))(?=.*(world)|)/

will match 'hello' wherever it may be, and will match 'world' if it's in the string.

Also if you're looking for words it's a good idea to use \b to indicate a word boundary, i.e

/(?i)(\bhello\b).*?(\bworld\b|$)/

This will stop it matching worldly, or helloid (is that a word!?)
Posted By: elroyK Re: /filter - 25/06/03 12:48 PM
Nope i don't want them matched in a particular order,or only whole words, so as it is now it works fine.
The only thing i was wondering, i read with s/ something you can have it replace matches with a string ? How would i do that ?
I want to replace a number at the beginning of the line with $asctime(number), and cut off the first three characters of another word..
© mIRC Discussion Forums