You can't do that with a textarea but you'd likely be happy with an alternative.
I used CodeMirror in a previous project and it worked well:
CodeMirror creates a syntax-highlighted editor but through lots of non-textarea elements like spans.
Use regex in js to find special character in an oninput function so that it check all character as they entered.it will return true if
special character found.
Then use a condition
If special character found (target the last character of div).style.color ="youfavcolor";