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:
perl -MRegexp::Debugger -e '"abcdef" =~ /(a|b) b+ c/'
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:
perl -MRegexp::Debugger -E 'Regexp::Debugger::rxrx(@ARGV)'
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex analysis
by kcott (Archbishop) on Aug 08, 2013 at 05:44 UTC | |
|
Re: Regex analysis
by davido (Cardinal) on Aug 08, 2013 at 00:12 UTC | |
|
Re: Regex analysis
by locked_user sundialsvc4 (Abbot) on Aug 07, 2013 at 23:38 UTC | |
|
Re: Regex analysis (rxrx bugs)
by Anonymous Monk on Aug 08, 2013 at 09:12 UTC |