在评估m//
或s///
表达式时,是否有方便的方法来获取正则表达式引擎状态的跟踪?
答案 0 :(得分:8)
是。将正则表达式引擎转为调试模式,它将打印它正在做的事情:
use re 'debug';
my $str = "abcdefg";
$str =~ m/[ef]+/;
其输出为:
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]+"