mIRC Home    About    Download    Register    News    Help

Topic Options
#192202 - 24/12/07 05:04 PM Regular expressions in on text
snabbi Offline
Ameglian cow

Registered: 03/09/03
Posts: 38
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

Top
#192203 - 24/12/07 05:06 PM Re: Regular expressions in on text [Re: snabbi]
Lindrian Offline
Pikka bird

Registered: 17/08/07
Posts: 13
Confirmed.

Top
#192206 - 24/12/07 05:51 PM Re: Regular expressions in on text [Re: snabbi]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
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)

_________________________
- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Top
#192212 - 24/12/07 07:22 PM Re: Regular expressions in on text [Re: argv0]
snabbi Offline
Ameglian cow

Registered: 03/09/03
Posts: 38
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.

Top
#192311 - 28/12/07 06:11 PM Re: Regular expressions in on text [Re: snabbi]
TropNul Offline
Babel fish

Registered: 09/05/07
Posts: 89
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
_________________________
tropnul

Top
#192359 - 30/12/07 12:01 AM Re: Regular expressions in on text [Re: TropNul]
Mpdreamz Offline
Hoopy frood

Registered: 27/04/04
Posts: 759
Loc: Arnhem, The Netherlands
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)
_________________________
$maybe

Top