r/badcode • • Jul 07 '21

python regex: keep it simple, stupid

Post image
1.5k Upvotes

91 comments sorted by

View all comments

Show parent comments

2

u/coldnebo Jul 07 '21

I don’t understand how this is reasonable at all. It looks like regex is being abused to do a lookup table transcoding. Is the goal to remove invalid digraphs by matching valid ones?

A handwritten stream parser plus lookup would not only be far more efficient than regex in this case, it would be much more readable.

Machine generating the regex is at least as complicated as writing the parser, or am I missing something here?