Teaching, rebuking, correcting & training in righteous web design.

Regluar Expressions Editors and Testing Apps.

May 26, 2004by meandean

Regular expressions are like a chain saw … a gas powered chain saw. At first, you’re deathly afraid of even touching it. When you do fire one up for the first time, it’s only after you’ve dressed yourself like a hockey goalie and have your spouse waiting just outside of your roped-off area with his or her their finger on the 911 speed dial button.

Once you realize that if you practice some common sense, that is you take time to think through what you’re trying to do first, regular expressions become your favorite power tool – just like your chain saw.

For example, now that I’m pondering a move to WordPress, I’ve got to port Scripturizer from Perl to PHP. Scott Yang has already done much of the work, but the regex needs to be expanded to include multiple references, e.g. Romans 10:9-10, 12:1-2 or Matthew 5:6-7, 9-12.

Debugging something like this can become incredibly frustrating using the code and test method. Not so much since I have both Perl and PHP installed on my local PC. Still, having tools to help construct, visualize and debug your regular expressions can help reveal hidden bugs, catch typos that snuck past your bleary gaze, and/or teach you how to use your chain saw – I mean regex – without cutting your foot clean off.

So here are some tools, tutorials and testers I found:

Desktop Tools:

Kiki – a free environment for regular expression testing (ferret). It allows you to write regexes and test them against a sample text, providing extensive output about the results.

I just wrote about this in my blog, but I think the easiest way to do regex is to make a state diagram. Having a picture to mentally follow makes things a whole lot easier in the debug phase. Then when you go to the checker to verify, you have a clearer understanding.

If you’re willing to shell out a little cash($30 US), I would recommend RegexBuddy. I literally went from clueless about regular expressions to comfortable within minutes. It also generates PHP, PERL, C# and a bunch of other types of code for you, which is neat.

I’ve just tested my old scripturizer for PHP, and references to multiple verses on the same book works fine for ESV on GNP’s site, as long as you use a coma ‘,’ to deliminate the verses. Multiple verses on different books would not work (like “Romans 5:8, Ephesians 2:8-9”) , as 2 separate links would be generated. Multiple verses does not currently work on Bible Gateway either as BG requires a semicolon ‘;’ between verses – but that can be easily hacked.

I am currently updating the old PHP scripturizer code to your 1.3 code base which supports short Bible book names. And I will also wrap it up as a WordPress plugin.

WordPress is nice, but I’ve found Textpattern to be even more awesome. Also, I’m attempting to port a Scripturizer php mod to a plugin in Textpattern (except it might require a modification to Textile, which is rather irritating.)