mIRC Home    About    Download    Register    News    Help

Topic Options
#247097 - 21/07/14 03:48 AM $regsub: intended behavior?
cyborg Offline
Bowl of petunias

Registered: 21/07/14
Posts: 2
Is this the intended behavior?

//echo 12 -ag $regsub(Replace myfixed., myfixed, fixed, %var) | echo 12 -ag VAR: %var

VAR: Replace myfixed.
(myfixed replaced with "myfixed" instead of "fixed".)

//echo 12 -ag $regsub(Replace Xyfixed., Xyfixed, fixed, %var) | echo 12 -ag VAR: %var

VAR: Replace fixed.
("Xyfixed" replaced with "fixed" as expected.)

//echo 12 -ag $regsub(Replace myfixed., /myfixed/, fixed, %var) | echo 12 -ag VAR: %var

("myfixed" replaced with "fixed" as expected.)

As seen above, surrounding the regular expressoin with /'s does avoid the issue.

I'm assuming it is related to the "m" in this:

"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 the 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-."

Though the requirement above is not stated for regular expression outside of events, unless I missed it. (Quite possible).

(BTW, what does the "m" prefix do? Probably something else I've missed.)

Thank you for your time.

#247098 - 21/07/14 04:03 AM Re: $regsub: intended behavior? [Re: cyborg]
Iire Offline
Babel fish

Registered: 06/08/13
Posts: 73
The m prefix sets the character that immediately follows it as the regex delimiter (i.e., the character that separates the pattern from the modifier flags).

For instance, if your pattern contains a lot of / characters, and you don't want to escape them every time, you could use the m prefix to set the delimiter to, say, ~

//noop $regex(http://forums.mirc.com/ubbthreads.php,m~https?://([^/]+)/([^/]+))~gi) | echo -ga $regml(1) - $regml(2)

The reason your first example didn't work is because without the default // delimiters, m was seen as a delimiter setter that made "y" the delimiter, and so the actual pattern being matched was "fixed". In example three, because you used the // delimiters, the m was just seen as a literal m.

#247113 - 21/07/14 04:18 PM Re: $regsub: intended behavior? [Re: Iire]
cyborg Offline
Bowl of petunias

Registered: 21/07/14
Posts: 2
Ah, thanks much for the info'.

Though I think a little addition in the help file such as "Absence of delimiters may lead to unexpected results" wouldn't hurt.

#247115 - 21/07/14 05:05 PM Re: $regsub: intended behavior? [Re: cyborg]
Loki12583 Online
Hoopy frood

Registered: 22/01/04
Posts: 1268
This behavior is not unexpected, it's well defined: just not in the help file.

It is beyond the scope of this help file to explain how Regular Expressions work.