in reply to Analyzing regular expression performance

Are there tools or general methods for breaking down an expression

The 'debug' mode of re will let you see how the expression is compiled, and how it behaves when matching. It is usually obvious to see where backtracking is taking place.

#! /usr/bin/perl use strict; use re 'debug'; print "easy\n" if 'simple' =~ /simple/; print "hard\n" if 'simple' =~ /^.[i-k]\lM(?:pla|plo|pl)(?:oink)?e$/;

Another trick is to "leave crumbs" is the pattern, to see how often the engine runs over a particular section of the pattern, for instance:

perl -le '(q(x) x 100) =~ /^x(((((x{2,5})x{2,5})x{2,4})x?)x?(?{$hit++} +))$/; print $hit'

• another intruder with the mooring in the heart of the Perl