Is there a convenient way to get a trace of the regex engine's states during the evaluation of a m//
or s///
expression?
BTW, I'm aware of that there is a Regexp::Debugger package available through CPAN (and it is amazingly cool), but I don't see a way to get anything like a trace from it; I don't want to step through a potentially huge number of steps.
Yes. Turn the regex engine into debug mode and it'll print what it's doing:
use re 'debug';
my $str = "abcdefg";
$str =~ m/[ef]+/;
Which gives an output of:
Compiling REx "[ef]+"
Final program:
1: PLUS (13)
2: ANYOF[ef] (0)
13: END (0)
stclass ANYOF[ef] plus minlen 1
Matching REx "[ef]+" against "abcdefg"
Matching stclass ANYOF[ef] against "abcdefg" (7 bytes)
4 <abcd> <efg> | 1:PLUS(13)
ANYOF[ef] can match 2 times out of 2147483647...
6 <abcdef> <g> | 13: END(0)
Match successful!
Freeing REx: "[ef]+"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With