Monday, March 10, 2014


AngularJS is civilization. And one demo application I thought to build for it was a regular expression workshop. We all know the problem with regexes: they're powerful but messy. It comes from the fact that they're one complexity level below context-free grammars (i.e., programming languages), so theoretically they shouldn't be able to get so complex that you can hurt yourself, and so everyone's at liberty to hack away.

I made RegexWorks as a test framework for regexes where you can easily do in-depth, at-a-glance debugging. You have space to enter text, which gets split into different lines (or however else you want), and all the regexes are applied to them in parallel. And you can add an arbitrary number of regexes that do matching or replacing. An output section next to the input shows you the result of running the regexes on each line.

The real magic is in the debug matrix at the bottom, that shows you the effect of each regex on each line, so you can track the effects of multiple cascaded substitutions and matchings. And it all uses AngularJS to get instant feedback without any messy event listening or DOM manipulation.

Because it uses AngularJS, however, it updates everything once you change anything. So it'd probably be a bad idea to paste, like, the last few days' worth of logs from your Apache server into the input and start futzing with the regexes. It won't run fast. Best to limit yourself to about a hundred sample lines that you want to hack with.

I set up some demo links that pre-fill everything to get you started. The first just has some 'foo'-'bar' text, and the second runs regexes over Hamlet's "To be or not to be" soliloquy.

No comments:

Post a Comment