Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

miyagawa (1653)

  (email not shown publicly)
AOL IM: bulknews (Add Buddy, Send Message)

Journal of miyagawa (1653)

Friday October 12, 2007
02:15 PM


[ #34663 ]


Is there a module to debug your regular expression, to compare the target string and an input regular expression one byte by one? It'd be useful if you have an existent code to do a pattern match against a big chunk of string and don't know why it doesn't match.

use Regexp::Debug;
my $string = "abcdefg";
my $regexp = qr/abcefg/; # Notice 'd' is missing
my $result = Regexp::Debug->compare($string, $regexp);
# $result would be an object or a string to
# indicate that the regexp stopped matching at 'abc'

It's the thing we regularly do, when the regular expression based screen scraping tool (BAD! Use Web::Scraper instead!) stops working. I open up 2 terminal screens, one with HTML output and one with regular expression. In the worst case I split the regular expression in a binary tree search fashion to find where it's broken.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.