mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
$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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
//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.

Joined: Aug 2004
Posts: 101
D
Vogon poet
Offline
Vogon poet
D
Joined: Aug 2004
Posts: 101
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?

Last edited by dr_Eamer; 07/09/04 12:41 PM.

Maybe I wake up one day to notice that all my life was just a dream!
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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


Gone.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Dec 2002
Posts: 788
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 788
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.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
I forgot completely about the $n syntax. Yeah in that case it's definitely not a bug.

Damn you, Perl! *shakes fist*


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard