mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2005
Posts: 30
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2005
Posts: 30
I'm trying to get $read to return the first thing in a file that does not match the specified fields.
For example, say the file had:

233
ABCD
X3
G

And I wanted it to exclude 233, ABCD, how would I return the first thing that didn't include those two (233 and ABCD are in variables)? I tried using a $read(filename.txt,r,/[^233]|[^ABCD]/) do it, but it didn't seem to work :\ (I'm probably just really bad at expressions :\ )

Thanks in advance as always,
-SnakeBite

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
$read(filename.txt,r,/(?!233|ABCD)/)

Joined: Aug 2005
Posts: 30
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2005
Posts: 30
When I tried that, it returned ABCD when it should've filtered it out :S

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Missed a character wink

Code:
$read(filename.txt,r,/[color:red]^[/color](?!233|ABCD)/)

Joined: Aug 2005
Posts: 30
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2005
Posts: 30
That only works if 233 or ABCD are the first characters.
What if they weren't? Or what if they were say, the second token with 32 as delimiter? Sorry I sound like a slavedriver now frown

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
The problem is that you need to have a fixed position somewhere frown
For example: $regex(ABCDE,/(?!ABC)/) returns 1 (a match is found) because BCD != ABC. $regex keeps trying all positions and checking for that untill it finds some location that satisfies all conditions...

Here's to fix the match to the start of the second space-delimited token (word)
//echo -s d $regex(all.kinds-of_stuff: ABCDdfg,/^[^ ]+\x20(?!233|ABCD)/)

To allow the second word to start with the given pattern but have something else after it:
//echo -s d $regex(alll.kinds.of_stuff: ABCDdfg,/^[^ ]+\x20(?!(?:233|ABCD)\b)/)

To filter out all occurrences of ABCD or 233 in the second word:
//echo -s d $regex(alll.kinds.of_stuff: sdfgABCDdfg,/^([^ ]+\x20(?!\w*(?:233|ABCD)))

To filter out all text with 233 or ABCD anywhere:
//echo -s d $regex(alll.kinds.of_stuff: sdfgABCDdfg,/^(?!.*(?:233|ABCD))/)
(Yes, the ^ at the start is required, otherwise it will match BCDdfg smile

Hope you can use these to produce something to your liking. I used the /echo stuff to test myself, you can filter out the /regex/ yourself I hope smile

Also, check out the PCRE manual from around line 1574 on, it contains everything you need to know about regex themselves, and that library is used in mIRC.


Link Copied to Clipboard