Books of Note

Practical Common
LispThe best intro to start your journey. Excellent coverage of CLOS.

ANSI Common
LispAnother great starting point with a different focus.

Paradigms of Artificial Intelligence
ProgrammingA superb set of Lisp examples. Not just for the AI crowd.

Wednesday, February 09, 2005

Easy regular expression development 

Every now and then, you find one of those utilities that makes you smack your forehead and say, "Now, why didn't I think of that?!" Such it was today when I found Edi Weitz's Regex Coach. A while ago, I downloaded Edi's well-written portable Perl-compatible regular expression library for Common Lisp (CL-PPCRE). The CL-PPCRE web page has a link to Regex Coach, which I glanced at once, but I didn't really read very well. At least to me, the name "Regex Coach" suggests a utility that will help you learn about regular expressions and how they match and parse strings, and so I probably glanced at it and moved on (I'm sure that Edi will nicely point out that it's all there in plain English--on a German web page, even--and I should have my eyes checked). In any case, it does that, but there's much more to this utility than a simple educational session. Simply, Regex Coach allows you to develop regular expressions incrementally (sound familiar with Lisp?).

I don't know about you, but I frequently have trouble when I'm writing out complex regular expressions. The syntax is terse and cryptic. There are multiple ways to specify various matching terms. It seems like I'm continually tweaking my expression string and then re-running my program with some sample input to verify that things are being matched the way that I intend, particularly for some odd corner cases of input strings. If I'm matching a really long expression, this can be quite involved. Now, Lisp's REPL makes this tons easier than it would be in a batch-compiled language like Java, C, or C++, but it's still slower than it needs to be.

The absolute genius (yes, Edi, you're a genius) of the Regex Coach is that it presents you with two main input fields, one for the regular expression string and a second for a sample string that you're trying to match. Given the inputs, the GUI graphically highlights portions of the sample string that match portions of the regular expression. Everything works interactively. Change the regular expression or the input string and the highlighting changes to suit. There is even a pane to single-step through the matching process where you can see how the regex engine matches various pieces of input in relation to each term in the regular expression.

Simply put, this utility is fantastic and will be a huge timesaver from here on out whenever I need to create a regular expression. Best of all, Regex Coach is written in Common Lisp (Lispworks) and uses Edi's CL-PPCRE library for all its matching, so you know that whatever syntax you come up with will be compatible with CL-PPCRE when you paste your regular expression into your Lisp code. Regex Coach works on both Linux (Motif-based) and Windows.

Did I mention that Edi is a genius?


Comments:


It sounds a bit like M-x re-builder RET in Emacs.
 


Yes, very similar. I hadn't realized that re-builder was in Emacs until you mentioned it. Regex Coach supports Perl-compatible regexes with compatibility with the CL-PPCRE library, so it's not quite a functional equivalent, but the basic idea is almost identical. Regex Coach also offers more than the basic regex highlighting that re-builder supplies, but that's the main feature and the one of most value for me. Now I know how to generate my elisp regexes!
 


Another good tool for developing Regular Expressions is The Regulator. It shows all of the matches in a third pane that you can click on one of them to highlight it in the input pane.

It is written in .Net and somewhat .Net-centric, but has proven itself very useful in developing for .Net's beast of a regex library.

There is also an option for ECMA Script which from my two seconds of research I believe is Perl compatible. Anyone know for sure?
 

Post a Comment


Links to this post:

Create a Link

This page is powered by Blogger. Isn't yours?