mIRC Home    About    Download    Register    News    Help

Print Thread
#247097 21/07/14 02:48 AM
Joined: Jul 2014
Posts: 2
C
cyborg Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
C
Joined: Jul 2014
Posts: 2
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.

Joined: Aug 2013
Posts: 81
I
Babel fish
Offline
Babel fish
I
Joined: Aug 2013
Posts: 81
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.

Joined: Jul 2014
Posts: 2
C
cyborg Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
C
Joined: Jul 2014
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.
laugh

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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.


Link Copied to Clipboard