I have been through many examples of syntax highlighting and I noticed that most of them use Regex. I like the idea of using Regex and all but I am puzzled as to how they know what words to highlight when the regex returns a match. My current method is very slow and eats up the text character by character and builds strings and tokens.

Anyone care to explain to me how that works?