mIRC Home    About    Download    Register    News    Help

Print Thread
#34537 07/07/03 01:23 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
var %x | .echo -q $regsub(text,/t/g,\\,%x) | echo -a %x
it doesn't replace the t's with \, why ?

also, can any1 tell me what does the \0 in regsub ?


#34538 07/07/03 08:07 AM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
This appears to be a bug. $asc(92) does not work and passing a %variable instead doesn't work either.

The problem here is that $regsub is looking for back-references \1 \2 etc, and doesn't seem to leave lone \'s alone. It also does not interpret the replacement text as a regular expression, so \\ != \. Khaled ought to fix this.

I believe \0 is a reference for the entire string.
//var %x, | .echo -q $regsub(xyz,/./g,\0,%x) | echo -a %x
This replaces each character with the entire original string.
returns: xyzxyzxyz

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
#34539 07/07/03 08:23 AM
Joined: Dec 2002
Posts: 169
J
Vogon poet
Offline
Vogon poet
J
Joined: Dec 2002
Posts: 169
Weird. I guess you can get around it using

var %x | .echo -q $regsub(text,/t/g,\999\\,%x) | echo -a %x

No idea why double \'s after a backreference works though.

#34540 07/07/03 10:20 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
thanks
Jerk can u tell me why your way works ?

#34541 07/07/03 10:32 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Because it seems that, for whatever reason, the "\\" sequence is translated to "\" only if there is text before or after it:

$regsub(text,/t/g,\\a,%x)
or
$regsub(text,/t/g,a\\,%x)
work.

The problem is obvious here. You keep the backslash but also the character(s) you chose to put before or after it (in this example, "a"). However, if you use the "\999" sequence as the set of characters that has to be before or after the \\, $regsub() replaces it with the 999th captured match, which of course doesn't exist. So, \\\999 is tranlsated to \. Pretty clever trick.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#34542 07/07/03 10:38 AM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
aha
thanks


Link Copied to Clipboard