I'm sick of Regex notation. It's ugly, unreadable, and impossible to debug. However, mathemeticians have been using Finite State Machines to design regular expressions for decades.
If I'm getting annoyed by regexes, I'll go and draw it out as a finite state machine by hand, and then have to translate the finite state machine into whatever hideous regex syntax I'm using today.
Is there a program that lets me design finite state machines and spit out a regex?
If you know Python, you can try greenery. The package fsm
is for finite state machines, and lego
is for regular expression objects. The two can be freely interconverted.
>>> from greenery import fsm
>>> x = fsm.fsm(
... alphabet={"1", "2"},
... states={"A", "B", "C", "D", "E"},
... initial="A",
... finals={"E"},
... map={
... "A": {"1": "C", "2": "A"},
... "B": {"1": "B", "2": "D"},
... "C": {"1": "E", "2": "C"},
... "D": {"1": "A", "2": "B"},
... "E": {"1": "C", "2": "D"}
... }
... )
>>> print(x.lego())
(1(11|2)*12(21*2)*1|2)*1(11|2)*1
I feel I should point out that your example finite state machine lacks both an initial state and any final states, so I guessed them. Also, an arbitrary FSM usually converts into a pretty horrible regular expression, and simplifying a regular expression is computationally difficult...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With