3 ms·
Animating Regular Expressions with Python and Graphviz
- aendruk 4y agoThis is fun, but I find I can’t meaningfully follow the animation unless I already understand the regular expression. So it seems the practical benefit comes not from the end product, but from the exercise of creating it.
- macintux 4y agoI think animations that don’t offer the user a way to step through them at their own pace are missing the point.
- RodgerTheGreat 4y agoToo bad the "User Input" flag in the GIF89a standard is rarely implemented.
- amitport 4y agoHi nice work! The presentation can be a little more clear that it is just an example of an implementation strategy. Regular expression engines are not always implemented using automata.
- jraph 4y agoRelated: I wrote Aude [1] (AUtomata DEmystifier) as a student. You can draw finite state machines with it. You can apply algorithms on those FSMs. You can run words on them. You'll see an animation of the word being run and you can choose the speed of the animation or run it step by step. You can translate them into regular expressions and translate regular expressions into FSMs. It'll use GraphViz to render the FSMs when you are not drawing them yourself. (since this is mainly for teaching, the regular expression language that it supports is very simple, it's not PCRE!) The animation in this article looks quite similar to the "Run word" feature in Aude, though the regular expression's elements of syntax like operators and parenthesis don't appear in FSMs produced by Aude. WebAssembly was not a thing, asm.js had just appeared. Aude uses a version of GraphViz compiled in asm.js to convert DOT strings to SVG. [1] https://aude.imag.fr/ https://aude.imag.fr/
- digisign 4y agoI've found if you can break up a regex into verbose form, and debug it on a app or site like regex101.com, you can figure out just about any expression. Then add comments with that understanding. That may not extend to the email address-parsing monstrosity that was given, but I think it would still help considerably.