I know very little about regex, but here's an example to handle the colors. I'm sure a similar method (and better set up regex) can just as easily do the rest of the control codes.
alias test {
var %pos1 = $pos($1-,http), %pos2 = $pos($right($1-,- $+ %pos1),$chr(32))
var %a = $left($1-,$calc(%pos1 - 1))
var %b = 11 $+ $mid($1-,%pos1,%pos2) $+
if ($regex(%a,/([0-9]{1,2})/g)) { var %color = $regml($regml(0)) }
var %c = %color $+ $right($1-,$calc($len($1-) - %pos1 - %pos2))
echo -a %a %b %c
}
Test case:
/test this is a 04colored 03link
http://www.mirc.com/ to get help
Now, as I said, I don't really know regex... this is really my first time coming up with anything that actually works with regex.
So, this definitely can be cleaned up ... a LOT. And I also didn't work too hard at making any of the rest look nice either. I was mainly just trying to get a working example of the regex part set up and just threw together the rest to show how it would work.
Also, this doesn't take into account certain situations (such as the use of Ctrl-O or multiple links) that may affect the output. However, it should show that obtaining the previous color shouldn't be too difficult. I'm looking forward to seeing a regex pro's example to see how far or close I am.
A final note -- You'd want to use a regex to match the URL instead of using "http". I just used that for a quick example.