Not sure if this is what you wanted but try it:
Code:
repl {
  var %s = (?:[]|(?:\\d\\d?(?:,\\d\\d?)?)?)*
  !.echo -q $regsub($2,/(?<=.)(?=.)/g,%s,%s) $regsub($1,$+(/,%s,/gi),$replace($3,\,\\,$,\$),%s)
  return %s
}
Usage is $repl(input string,before text,after text)
Example: //var %string = t03his text is l04ots of colors a09,07nd other burk c0odes | echo -a %string | echo -a $repl(%string,colors,COLORS)

$repl()'s limitation is that the second param ("before text") must not contain any regex special character (like \, +, ?, * etc). If you don't like this, you can use $replex(); that huge $replace() in it takes care of the special chars.
Code:
replex {
  var %s = (?:[]|(?:\\d\\d?(?:,\\d\\d?)?)?)*, %2 = $&
    $replace($2,\,\\,^,\^,$,\$,.,\.,[,\[,$chr(40),\ $+ $chr(40),$chr(41), $&
    \ $+ $chr(41),?,\?,*,\*,+,\+,$chr(123),\{,$chr(125),\})
  !.echo -q $regsub(%2,/(?<=.)(?=.)/g,%s,%s) $regsub($1,$+(/,%s,/gi),$replace($3,\,\\,$,\$),%s)
  return %s
}