|
|
Joined: Feb 2003
Posts: 12
Pikka bird
|
OP
Pikka bird
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:
//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"
//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.
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Feb 2003
Posts: 12
Pikka bird
|
OP
Pikka bird
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.
|
|
|
|
Joined: Feb 2003
Posts: 12
Pikka bird
|
OP
Pikka bird
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.
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
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:
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
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
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
LOL "crossposting weirdness"
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
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!
|
|
|
|
|
|