湖上湖
使用Perl 5.10 , use re 'debug';. (或者debugcolor,我无法在Stack Overflow上正确格式化输出。)$ perl -Mre = debug -e'“foobar”=〜/(。)\ 1 /'编译REx“(。)\ 1”最终计划: 1:OPEN1(3) 3:REG_ANY(4) 4:关闭1(6) 6:REF1(8) 8:结束(0)明娜1将REx“(。)\ 1”与“foobar”匹配 0 <> <foobar> | 1:OPEN1(3) 0 <> <foobar> | 3:REG_ANY(4) 1 <f> <oobar> | 4:CLOSE1(6) 1 <f> <oobar> | 6:REF1(8) 失败... 1 <f> <oobar> | 1:OPEN1(3) 1 <f> <oobar> | 3:REG_ANY(4) 2 <fo> <obar> | 4:CLOSE1(6) 2 <fo> <obar> | 6:REF1(8) 3 <foo> <bar> | 8:END(0)匹配成功!释放REx:“(。)\ 1”此外,您可以向正则表达式添加空格和注释,以使它们更具可读性。在Perl中,这是使用/x修饰符完成的。有pcre,有PCRE_EXTENDED旗帜。"foobar" =~ / (.) # any character, followed by a \1 # repeat of previously matched character/x;pcre *pat = pcre_compile("(.) # any character, followed by a\n" "\\1 # repeat of previously matched character\n", PCRE_EXTENDED, ...);pcre_exec(pat, NULL, "foobar", ...);