This comment[1] from ianlancetaylor on Github appears to provide reasons as to why the standard Go implementation of regex is less than optimal.<p><i>As you say, in a language like Python, the regexp engine is implemented in C. So you are comparing a somewhat tuned Go implementation with a highly tuned C implementation. You also need to consider the characteristics of the engine. Go has chosen to follow the re2 path (not surprising, since Russ Cox is a major author of both Go and re2). re2 has much better performance characteristics than some other regexp engines, in that it never has an exponential slowdown, but that comes at a cost for other regexps. Even then, the C++ re2 implementation has many optimizations that are not in the Go implementation.</i><p>[1] <a href="https://github.com/golang/go/issues/19629#issuecomment-288152974" rel="nofollow">https://github.com/golang/go/issues/19629#issuecomment-28815...</a>
This could be useful for writing lexers. Although I typically need to interleave some "decoding" with proper lexing (like decoding escape sequences in strings, universal character names in identifiers etc.), which would make it harder, when you want to do it in a single pass.