|
Joined: Jun 2003
Posts: 36
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2003
Posts: 36 |
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?
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
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
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Jun 2003
Posts: 36
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2003
Posts: 36 |
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.
|
|
|
|
Joined: May 2003
Posts: 215
Fjord artisan
|
Fjord artisan
Joined: May 2003
Posts: 215 |
Try use /filter -afw that's what I've used on a couple of occassions and it seems to sort the contents fine.
- Jason
|
|
|
|
Joined: Dec 2002
Posts: 77
Babel fish
|
Babel fish
Joined: Dec 2002
Posts: 77 |
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)/
|
|
|
|
Joined: Jun 2003
Posts: 36
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2003
Posts: 36 |
/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.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
/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.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Jun 2003
Posts: 36
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2003
Posts: 36 |
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 ?
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
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
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Jun 2003
Posts: 36
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2003
Posts: 36 |
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 ?
|
|
|
|
Joined: Jun 2003
Posts: 36
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2003
Posts: 36 |
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.
|
|
|
|
Joined: Dec 2002
Posts: 77
Babel fish
|
Babel fish
Joined: Dec 2002
Posts: 77 |
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!?)
|
|
|
|
Joined: Jun 2003
Posts: 36
Ameglian cow
|
OP
Ameglian cow
Joined: Jun 2003
Posts: 36 |
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..
|
|
|
|
|