mIRC Homepage
Posted By: bynw $regex help - 09/03/05 01:07 AM
I have the following in a script (this is only a portion)

$regex($5,(.~[a-z]{1}[0-9]{3,4}@*))

It is looking at the [email]ident@host[/email] information of a user. And more specifically at just the ident. Is there a way to limit it to only finding the matches listed? Which would be a letter followed by 3 or 4 numbers ... but I don't want it to trigger on an ident of a letter folled by 3 or 4 numbers that are in turn followed by something else.

i.e.

~y234 (trigger on this ident)
~k3322 (trigger on this ident)

~d893dklal33 (not triggering on this ident)

Thanks in advance
Posted By: tidy_trax Re: $regex help - 09/03/05 01:25 AM
Code:
$regex($5,/^~?[a-z]\d{3,4}(?:@.*)?$/)
Posted By: bynw Re: $regex help - 09/03/05 01:48 AM
can you explain that for me? for my future understanding
Posted By: tidy_trax Re: $regex help - 09/03/05 01:59 AM
The ^ and $ (When used how they are here) mean the string has to be an exact match.

~? means the ~ can be in the string but it doesn't have to be.

[a-z] is a single lowercase letter.

\d{3,4} is 3 or 4 digits, \d is the same as [0-9].

(?:@.*)? means the host part of an address can be there but doesn't have to be, the ?: just means you cannot reference the match it found later using $regml() and @.* means there can be 0 or more characters following the @.
Posted By: bynw Re: $regex help - 09/03/05 02:19 AM
Thanks... just one more thing ... when the string is seen by mIRC it's enclosed in ( )

so the string really is
*** Client connecting: scrawl06 (~scrawl@data.searchirc.org) on port 6667

and I'm just looking at the (~scrawl@data.searchirc.org) part.
Posted By: tidy_trax Re: $regex help - 09/03/05 02:22 AM
Code:
$regex($5,/^\50~?[a-z]\d{3,4}(?:@.*)?\51$/)


\50 is octal for (.

\51 is octal for ).
Posted By: Kelder Re: $regex help - 10/03/05 02:36 PM
Replace
$regex($5,/^\50~?[a-z]\d{3[color:red],4}(?:@.*)?\51$/)[/color]
with either
var %re = /^\50~?[a-z]\d{3,4}(?:@.*)?\51$/
$regex($5,%re)

or
$regex($5,/^\50~?[a-z]\d{3[color:green] $+ $chr(44) $+ 4}(?:@.*)?\51$/)
[/color]

Those commas always get stuff complicated mad

The first way is often better if you don't want to spend hours figuring out what mIRC wil parse and what not for a complicated regex.
(also watch those : in regex for on TEXT events etc.
Posted By: Sigh Re: $regex help - 10/03/05 03:09 PM
Or simply:

Code:
$regex($5,/^\(~?[a-z]\d{3,4}(?:@.*)?\)$/)


The use of parentheses (in place of their octal escapes) accomplishes the same thing, and causes the comma to be treated as part of the string, not as a parameter separator for $regex

To avoid a comma in this case, using \d{3}\d? is another option
© mIRC Discussion Forums