mIRC Homepage
Posted By: cyborg $regsub: intended behavior? - 21/07/14 02:48 AM
Is this the intended behavior?

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

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

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

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

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

Result:
("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.
Posted By: Iire Re: $regsub: intended behavior? - 21/07/14 03:03 AM
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, ~

Code:
//noop $regex(https://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.
Posted By: cyborg Re: $regsub: intended behavior? - 21/07/14 03:18 PM
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.
laugh
Posted By: Loki12583 Re: $regsub: intended behavior? - 21/07/14 04:05 PM
This behavior is not unexpected, it's well defined: just not in the help file.

Quote:
It is beyond the scope of this help file to explain how Regular Expressions work.
© mIRC Discussion Forums