Replace string operations with regex

Don't mind me, I'm just practicing too.

I think regexes are a better match (hah!) to this kind of problem.

TODO: move the compilation steps to somewhere where they are run only once.