mIRC Homepage
Posted By: SnakeBite34 $read return something NOT specified - 13/12/05 12:03 AM
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
Posted By: hixxy Re: $read return something NOT specified - 13/12/05 12:35 AM
Code:
$read(filename.txt,r,/(?!233|ABCD)/)
Posted By: SnakeBite34 Re: $read return something NOT specified - 13/12/05 01:28 AM
When I tried that, it returned ABCD when it should've filtered it out :S
Posted By: hixxy Re: $read return something NOT specified - 13/12/05 05:41 AM
Missed a character wink

Code:
$read(filename.txt,r,/[color:red]^[/color](?!233|ABCD)/)
Posted By: SnakeBite34 Re: $read return something NOT specified - 13/12/05 11:09 PM
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
Posted By: Kelder Re: $read return something NOT specified - 14/12/05 09:57 AM
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.
© mIRC Discussion Forums