mIRC Home    About    Download    Register    News    Help

Print Thread
#22233 04/05/03 08:07 AM
Joined: Feb 2003
Posts: 12
A
ash Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Feb 2003
Posts: 12
I've noticed some weirdness in the behaviour of the $regsub identifier. The items matched in parantheses can be used with \1 \2 etc but mirc identifiers fail to treat them as numbers. For example:
Code:
  
//set %decode hiya #23 wat #40 up | var %t = $regsub(%decode, /#([a-fA-F0-9]{2})/g, $iif(\1,$ifmatch), %decode) | echo -a %decode

echos "hiya 23 wat 40 up"

Code:
 
//set %decode hiya #23 wat #40 up | var %t = $regsub(%decode, /#([a-fA-F0-9]{2})/g, $iif(\1,$calc($ifmatch + 1)), %decode) | echo -a %decode
 

echos "hiya 0 wat 0 up"

$calc does not recognise it as a numeric value.

Any identifier that does something with a number fails as if it were null or just random text. For example $chr(\1) doesn't work, but string identifiers like $len, $+ etc handle it with no problems.

#22234 04/05/03 10:14 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
If you put an identifier there, mIRC parses the identifier outside of the regsub. What gets passed, to the $calc() in this case, is the literal "\1", which isn't a number.

#22235 04/05/03 10:19 AM
Joined: Feb 2003
Posts: 12
A
ash Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Feb 2003
Posts: 12
That's not true. Try with string identifiers, it works fine. I think there's a bug where mIRC isnt converting strings to numbers when they've came from a regex match.

#22236 04/05/03 10:33 AM
Joined: Feb 2003
Posts: 12
A
ash Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Feb 2003
Posts: 12
Sorry nimue looks like you are actually correct. The string identifiers i was using (like $str) were getting the \1 and returning say '\1\1\1\1\1' and then regsub will replace the return value with the matches. I think mIRC should have an identifier for the matches in $regsub.. even $1 $2 etc would be ok. $regml only returns the first match so it wouldn't work for global substitutions.

Last edited by ash; 04/05/03 10:39 AM.
#22237 04/05/03 10:36 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
/alias bgk echo -a $1 | return $replace($1,l,w)
//var %a = hello world | !.echo -q $regsub(%a, /(hello)/g,$bgk(\1) + \1,%a) | echo -a %a
\1
hello + hello world
Why is the first word "hewwo"? :tongue:

#22238 04/05/03 10:41 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
well, $str() makes a string of "\1", e.g. \1\1\1\1\1, which is perfectly ok for regsub.
//var %a = hello world | !.echo -q $regsub(%a, /(hello)/g,\1\1\1\1\,%a) | echo -a %a
hellohellohellohello world

#22239 04/05/03 10:45 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
LOL "crossposting weirdness" smile

#22240 06/05/03 11:26 PM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
$regsub DOES NOT evaluate \1 \2 \3 etc back-references, so you CANNOT make string manipulations before the reference gets placed.

$regsub(abcdefghijklmnop, /(def)/, $upper(\1), %string)
%string == abcdefghijklmnop
%string != abcDEFghijklmnop
BECAUSE : $upper(\1) == \1
NOT: $upper(def) == DEF

$upper will never see the actual string being referenced, only the literal \1 you placed in there. $upper is an evaluated identifier and \1 is simply a placeholder on an entirely different level of processing. Hope this makes more sense.

There is no bug here.

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!

Link Copied to Clipboard