I leave this here as a reminder, that just because you know your regex does not mean you should implement a LSP soly using it for parsing and than do tokenization and compiling in one step.
Read up on how to do this next time and use some libraries for the heavy lifting.