mIRC Homepage
$regsub will fail to even match if the sub-text (after evaluation) contains a $.

//var %result, %e = $regsub(moo,/o/g, s, %result) | echo -a %e %result
will correctly echo 2 mss

//var %result, %e = $regsub(moo,/o/g, $me, %result) | echo -a %e %result
will correctly echo 2 mmynickmynick

However if a $ is put in the substitution text it will fail. ie.
//var %result, %e = $regsub(moo,/o/g, $, %result) | echo -a %e %result
//var %result, %e = $regsub(moo,/o/g, $!me, %result) | echo -a %e %result
//var %result, %e = $regsub(moo,/o/g, a$a, %result) | echo -a %e %result
//var %result, %e = $regsub(moo,/o/g, $chr(36), %result) | echo -a %e %result
will all echo 0 moo

Tested with 6.15 and 6.16.
//var %r, %e = $regsub(moo,/o/g, \$, %r) | echo -a %e %r

The '\' will escape the $.

$regsub(moo,/o/g, \ $+ $chr(36), %r) also works.

Eamonn.
Works if escaped with '\'.
eg.
//var %result, %e = $regsub(moo,/o/g, a\$a, %result) | echo -a %e %result
//var %result, %e = $regsub(moo,/o/g, \ $+ $chr(36) , %result) | echo -a %e %result


Edit: Too late... Darn! :tongue:
Isn't it still a bug to be corrected though?
Quote:
Isn't it still a bug to be corrected though?

- I think so. As far as I know the only special meaning of $ in PCRE is as the end-of-line metacharacter, but I can't see how that has any relevance within the context of the sub-text parameter, and even if it did then why doesn't the beginning-of-line metacharacter ^ require the same treatment? I can't see any reason for characters to be treated specially inside that parameter except backslash since it can be used for back-references and a few other things.

Oh well. Thanks to both of you for the workaround.
Reply to Coolkill and dr. Eamer:

starbucks is well aware of the escape character, he's showing a bug nevertheless, as dr. Eamer points out.

Greets
Just to clarify why $ needs to be escaped:

//var %a, %b = $regsub(bc,/(b)c/,a$1,%a) | echo -a %a

$1, $2 etc work like \1, \2. This possibly comes from PCRE's compatibility with Perl (in which $1 and \1 are almost the same thing when used as "subtext"), although I don't know if the special meaning of $ in $regsub() is downright PCRE or just Khaled's own addition, in the spirit of that compatibility (I suspect the latter).
Firstly i'm unsure how you became their official spokesperson but nevertheless.. they were merely pointing out a bug, and as i'm sure you can appreciate users of this forum are all at completely different levels, in terms of scripting ability and knowledge.

As a result an alternative is always given to ensure the poster is aware of the solution, in addition the actual outcome of using a $ as a parameter could very well have been intentional or not concidered a bug in the first place so you should never jump to conclusions.

Eamonn.
I forgot completely about the $n syntax. Yeah in that case it's definitely not a bug.

Damn you, Perl! *shakes fist*
© mIRC Discussion Forums