mIRC Homepage

Quick question regarding a regex line...

Posted By: Div

Quick question regarding a regex line... - 16/02/07 03:56 PM

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!
Posted By: starbucks_mafia

Re: Quick question regarding a regex line... - 16/02/07 04:25 PM

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)
Posted By: Div

Re: Quick question regarding a regex line... - 16/02/07 04:34 PM

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)
Posted By: starbucks_mafia

Re: Quick question regarding a regex line... - 16/02/07 05:01 PM

You can still use capturing parentheses around the expression.

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