First problem I can see using $pos($1-,$chr(3)) is that it returns the first position, so if there's more than one $chr(3) you might not get the correct colour codes. Additionally, this doesn't take into account bold, underlining, or reverse character codes.