As someone said earlier, you need a lexer to break the text down into it’s Lua “components” aka tokens.
Lucky for you, I open sourced one!
Using that, you can run the TextBox.Text through the lexer and create colored TextLabels based on the resulting token stream for your syntax highlighting!