mIRC Home    About    Download    Register    News    Help

Print Thread
Regular expressions in on text #192202
24/12/07 05:04 PM
24/12/07 05:04 PM
Joined: Sep 2003
Posts: 38
S
snabbi Offline OP
Ameglian cow
snabbi  Offline OP
Ameglian cow
S

Joined: Sep 2003
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

Re: Regular expressions in on text [Re: snabbi] #192203
24/12/07 05:06 PM
24/12/07 05:06 PM
Joined: Aug 2007
Posts: 13
L
Lindrian Offline
Pikka bird
Lindrian  Offline
Pikka bird
L

Joined: Aug 2007
Posts: 13
Confirmed.

Re: Regular expressions in on text [Re: snabbi] #192206
24/12/07 05:51 PM
24/12/07 05:51 PM
Joined: Oct 2003
Posts: 3,918
Montreal, QC, Canada
A
argv0 Offline
Planetary brain
argv0  Offline
Planetary brain
A

Joined: Oct 2003
Posts: 3,918
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"
Re: Regular expressions in on text [Re: argv0] #192212
24/12/07 07:22 PM
24/12/07 07:22 PM
Joined: Sep 2003
Posts: 38
S
snabbi Offline OP
Ameglian cow
snabbi  Offline OP
Ameglian cow
S

Joined: Sep 2003
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.

Re: Regular expressions in on text [Re: snabbi] #192311
28/12/07 06:11 PM
28/12/07 06:11 PM
Joined: May 2007
Posts: 89
T
TropNul Offline
Babel fish
TropNul  Offline
Babel fish
T

Joined: May 2007
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
Re: Regular expressions in on text [Re: TropNul] #192359
30/12/07 12:01 AM
30/12/07 12:01 AM
Joined: Apr 2004
Posts: 759
Arnhem, The Netherlands
M
Mpdreamz Offline
Hoopy frood
Mpdreamz  Offline
Hoopy frood
M

Joined: Apr 2004
Posts: 759
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