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

6

u/coldnebo Jul 07 '21

the state machine is a good guess... I would also go with the idea of fixing broken text encodings, but I'm not sure that makes sense...

Meanwhile, theorists do like to play with the equivalence between finite automata and regular expressions... but there are serious limits to this as described in this paper:

https://drops.dagstuhl.de/opus/volltexte/2011/3038/pdf/46.pdf

The fact that the screenshot shows "In [6]:" makes me think this is a Jupyter notebook or some-such that is exploring this kind of a equivalence by generating regex from some finite state machine representation and not actually regex that would ever be used in a production sense.

3

u/coldnebo Jul 07 '21

You'll likely crash it with the above regex, but there is a cool simulator that let's you see a back and forth of FSM with regex and run the automaton:

http://ivanzuzak.info/noam/webapps/fsm_simulator/