Regular expressions in on text

Posted by: snabbi

Regular expressions in on text - 24/12/07 05:04 PM

Hi there,

I noticed that you are not able to use brackets in an on text event with regular expressions. This makes it impossible to use grouping. I think it is a bug, but perhaps there is a workaround.

I have tried to solve it with $chr(40) and stuff but haven't found a solution yet.

Using mirc 6.3 and example code:
on $*:TEXT:/(?:a)/:#: { echo -a test } <-- doesn't work
on $*:TEXT:/a/:#: { echo -a test } <-- does work
Posted by: Lindrian

Re: Regular expressions in on text - 24/12/07 05:06 PM

Confirmed.
Posted by: argv0

Re: Regular expressions in on text - 24/12/07 05:51 PM

The issue isn't from the brackets. Grouping is in fact allowed in the matctext, and works.

You cannot use : inside the text of a matchtext, as mIRC will parse that as the end of the matchtext delimiter, that is why your example fails.

The following example proves that it works fine:

Code:
on $*:TEXT:/(.)/:#:echo -a $regml(1)

Posted by: snabbi

Re: Regular expressions in on text - 24/12/07 07:22 PM

This makes sense, thnx

Still I think mIRC could ignore the : inside the / / of the pattern. Thnx though. No backrefs are needed but it is a workaround for grouping.
Posted by: TropNul

Re: Regular expressions in on text - 28/12/07 06:11 PM

I'm not sure if I'm right because I didn't test this but maybe you're using the regular expression facility in events incorrectly.

According to the help file:
Originally Posted By: mIRC's help file

The $ prefix

Indicates that the matchtext section of a definition contains a regular expression.

on $*:TEXT:m/regular expression/switches:#:/echo message: $1-

The 'm' and switches are optional. The // are required. If switches are used they must be standard PCRE switches, otherwise the match will fail. You can use switch 'S' to strip control codes from $1-.


Rather than just using /pattern/options, why not use m/pattern/options ? The leading m is used by the PCRE library to allow change in the expression's delimiters. Thus, with the leading m, one could write m@pattern@options, and this would function correctly if no '@' or atleast the '@'s are escaped if present in the pattern.

What I think is that mIRC uses this PCRE possibility to know where to stop its parser when parsing an event's header. Although the help file says that the 'm' is optional (which is true though), maybe it can be used when you want to include a ':' in your pattern. smile

I'm just supposing all that without any tests being done. Sorry if I'm not right. :s

An for the new year, Have Good Times !

Cordialement
Posted by: Mpdreamz

Re: Regular expressions in on text - 30/12/07 12:01 AM

That wouldn't work, mIRC parses the line first tokenizing by : ( i assume)

i.e:
on $*:TEXT:m/:/:#:echo -a message: $1-
would mess up the token count.

so even if you did
on $*:TEXT:m@:@:#:echo -a message: $1-
It would break it.

a simple alternative is to use \072 for :
on $*:TEXT:/\072/:#:echo -a message: $1-

or if your really concerned about backreferencing

on $*:TEXT:$(/(? $+ $chr(58) $+ a){3}(b)/):#:echo -a message: $1- regml: $regml(0) $regml(1)