mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
Hi all,

I'm trying to implement the following line:
Code:
$regex($1,/([(-_][A-Z]{2}[-_)])/g)


But when testing it seems to also match for _5AD_ while it should only match on _AD_
Most likely it's to do with those brackets... but I'm not capable of getting around that.
(and yes, I want them to be valid for (AD) too, so they have to remain there.)

Thanks alot in advance!

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The problem is that you're using a hyphen "-" in the middle of a character set "[(-_]". When used between two characters in a character set, "-" defines a range for all characters between the codepoints (ASCII numbers) of the two characters. In your case it's between "(" (codepoint: 40) and "_" (codepoint: 95), meaning all characters with codepoints between 40-95 will be matched (the number 5 happens to be codepoint 53).

The solution is simple: put the "-" at the end of the character set so that it's clear it isn't meant to define a range.

Code:
$regex($1,/([(_-][A-Z]{2}[-_)])/g)


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Aug 2005
Posts: 31
D
Div Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 31
Hmm...

Ok thanks... however, it seems that doing this will also stop my $regml() replies from working.

Code:
//echo -a $regex(blah_blah-5AD_ugh-AD-,/[(_-][A-Z]{2}[-_)]/g) // $regml(1)

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
You can still use capturing parentheses around the expression.

//echo -a $regex(blah_blah-5AD_ugh-AD-,/([(_-][A-Z]{2}[-_)])/g) // $regml(1)


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard