mIRC Homepage

regsub vartext backreferences followed by digits

Posted By: KyD

regsub vartext backreferences followed by digits - 04/08/03 02:43 AM

$regsub(test,abc,(b|d),\12,%var)
the intention here is to put the digit '2' behind the first 'b' or 'd' in a string.

the regsub above won't work because mirc interprets "\12" as the 12th backreference, not as the 1st followed by the digit '2'.

is there a way of getting around this?
Posted By: KyD

Re: regsub vartext backreferences followed by digits - 04/08/03 02:51 AM

oops double thread, we had a misunderstanding in who was to post the question here on the forum.
sorry about this.
Posted By: codemastr

Re: regsub vartext backreferences followed by digits - 04/08/03 03:05 AM

I didn't really think about it much, but it seems mIRC doesn't allow _any_ regex features in the "replace with" part other than \#, so the only thing I could come up with is something like:

$regsub(test,abc,(b|d),\1 $+ $chr(255),%var)
%var = $replace(%var,$chr(255),2)

Since character 255 is the character for the delete key, you can be reasonably sure that will not appear in your text. It's not a good way to do it, but it works.
Posted By: lammkott

Re: regsub vartext backreferences followed by digits - 04/08/03 09:52 PM

Quote:
Since character 255 is the character for the delete key...


$chr(255) on fonts like Tahoma is a and on fonts like Terminal it's a non-breaking space. That's how mIRC returns it anyway.
Posted By: codemastr

Re: regsub vartext backreferences followed by digits - 04/08/03 09:56 PM

Err indeed, you're right, no idea why I said 255, I meant 127
Posted By: qwerty

Re: regsub vartext backreferences followed by digits - 04/08/03 09:56 PM

Depending on the purpose of this, it could be better to use a character that cannot be in IRC text. Most of the times I use $lf or $cr.
Posted By: ScatMan

Re: regsub vartext backreferences followed by digits - 04/08/03 11:54 PM

if \999 is the maximum matches so why \1\9992 doesn't work ?

Posted By: starbucks_mafia

Re: regsub vartext backreferences followed by digits - 05/08/03 12:17 AM

Well for one thing because technically PCRE can capture up to 65535 matches. Plus it would just generally be bad syntax (IMO) to behave like that in that situation.
Posted By: ScatMan

Re: regsub vartext backreferences followed by digits - 05/08/03 12:58 AM

but that's the only way
replacing it with other character is a bad idea
Posted By: starbucks_mafia

Re: regsub vartext backreferences followed by digits - 05/08/03 01:09 AM

That part is parsed by the PCRE engine anyway, so it's not like mIRC can really do much about that.
© 2019 mIRC Discussion Forums