I was thinking from a performance point of view, text manipulation would have been much less intensive than this
– SomebodyOnEarthJan 11 at 23:19

1

Compared to the CPU time needed for the parsing process altogether, a recursive-descent into the result isn't typically going to be all that expensive. And frankly, if you care so much about performance that you're willing to give up correctness and conceptual simplicity on its behalf, Python is probably the wrong language for your job altogether.
– Charles DuffyJan 11 at 23:39