Perhaps old news to some, but a search didn't show this anywhere in the Monastery yet. So... Found a really interesting tool on CPAN to analyse perl regex matching: Regexp::Debugger.

You run it in a terminal and it interactively steps through the regex showing you each stage of the pattern matching. More importantly it shows you where a lot of back tracking is happening which can be the reason for slow execution.

Without images it's tough to appreciate how cool and useful this can be. If you haven't seen this before grab a copy and run something like this from your terminal:

And then just press space bar to step through the matching process. But there are many more features than that, press '?' to see all the keyboard options. That is a rather pedestrian example, it gets much more exciting when you have embedded code execution and lots of subgroups.

To top it off it has a REPL mode that allows you to type in a string and a regex on the fly:

Where you can then enter a regex with '/', and a string with single-quote, and then start the process with 'm'. Press q to return to the start screen to adjust your regex or string... rinse and repeat.

Thank you for a good write-up of a very interesting find! XP++ ... (And who-cares if it is “old news” to someone-else: it is timely and useful to The Center of My Personal Programming Universe™ ;-) and betcha I’m not alone.)