sure, you could quite easily match (\w+) in between '@' and '(', then use $findtok() etc. to map the colour name to its colour code.

see, once you start throwing new colours in the mix - allowing a variety of colours in the middle of a variety of other colours - you're going to run into problems when it comes to colour preservation, since you can't always revert back to green once the new coloured text has been substituted in.

there is a solution to this which also lends itself quite nicely to support for nested colour groups. you can use a single regular expression to find the dominant foreground & background colours (if any) before the next @colour() group, then match the group according to a specific set of rules. when you substitute the text back in, you can then append the colour codes you saved to have it revert back to the correct colours:

alias @colour {

  var %cols =                      $&
    white                       |( $&
    black                       |( $&
    (?:navy|dark)blue|navy      |( $&
    green                       |( $&
    red                         |( $&
    burgundy|brown              |( $&
    purple                      |( $&
    orange                      |( $&
    yellow                      |( $&
    lime|(?:l|br)ightgreen      |( $&
    teal|turqoise               |( $&
    aqua|(?:l|br)ightblue       |( $&
    (?:royal)?blue|royal        |( $&
    pink|fuchsia                |( $&
    gr[ea]y                     |( $&
    silver                         $&

  var $&
    %tx = $1                                                                           , $&
    %re = /^ (?|\x03(\d\d?)(?:,(\d\d?))?|[\x03\x0F]()()|.)*? (?(1)|())(?(2)|())          $&
    	  \K @ (?=\w*(\(((?>(?5)|[^()])*?)\))) ( %cols ) \5 /xi                        , $&
    %sb = $eval( $+($chr(3), $fix($calc(\0 - 5)), $iif(\2 != $null, $chr(44) $+ 99),     $& 
          \4$chr(3), $fix($int(\1 99)), $iif(\2 != $null, $chr(44) $+ $fix(\2))) , 0)

  while ($regsubex(col, %tx, %re, [ %sb ] ) != %tx) %tx = $v1

  return %tx

alias -l fix return $mid(0 $+ $1, -2)

%cols contains the names of colours ordered exactly as they appear in the colour palette. you may modify that list to reflect your personal naming convention, i've just thrown mine in for fun ;P if you do change them, don't add any (capturing groups) since that'll affect the rest of the code. stick to (?:non-capturing groups) as in (?:navy|dark).

so, because of the while loop, you can now nest your groups:

//echo -a $@colour(4red text @blue(blue text @red(more red!) back to blue @orange(some orange)) red text preserved)


red text blue text more red! back to blue some orange red text preserved

"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde