I strongly doubt the AST would be needed. You could probably do this in a trivial loop state machine. It can&#x27;t even be called laziness: that regex took time to work out - far longer than a switch-based state machine would have taken to write in the first place.<p>Aside: out of curiosity it would have been interesting to see how a Thompson NFA[1] would have dealt with this.<p>[1]: <a href="https:&#x2F;&#x2F;swtch.com&#x2F;~rsc&#x2F;regexp&#x2F;regexp1.html" rel="nofollow">https:&#x2F;&#x2F;swtch.com&#x2F;~rsc&#x2F;regexp&#x2F;regexp1.html</a>