|
Joined: Dec 2002
Posts: 2,884
Hoopy frood
|
OP
Hoopy frood
Joined: Dec 2002
Posts: 2,884 |
$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.
|
|
|
|
Joined: Dec 2002
Posts: 787
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 787 |
//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
Vogon poet
|
Vogon poet
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.
|
|
|
|
Joined: Dec 2002
Posts: 2,884
Hoopy frood
|
OP
Hoopy frood
Joined: Dec 2002
Posts: 2,884 |
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.
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
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
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
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).
|
|
|
|
Joined: Dec 2002
Posts: 787
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 787 |
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,884
Hoopy frood
|
OP
Hoopy frood
Joined: Dec 2002
Posts: 2,884 |
I forgot completely about the $n syntax. Yeah in that case it's definitely not a bug.
Damn you, Perl! *shakes fist*
|
|
|
|
|