虽然有许多用于测试正则表达式的良好在线和离线工具,但我还没有找到一个工具(除了RegexBuddy),它让我看到正则表达式引擎找到匹配的步骤(或者发现没有匹配, 对于这个问题.)
有谁知道这样做的任何工具?我最初排除RegexBuddy的原因是因为它是商业性的,我宁愿在我决定支付之前查看我的选项.
为了使我想要的更清楚,这里是RegexBuddy的截图(来自他们的主页):http: //img166.imageshack.us/img166/1272/debug.png
在 Perl 中你总是可以use re 'debug';或者use re 'debugcolor';
例如,如果您将以下内容输入到 Perl 中:
use strict;
use warnings;
use 5.010;
use re 'debug';
# using the same strings as the question's image for reference:
my $str = 'Even if I do say so myself: "RegexBuddy is awesome"';
$str =~ /(Regexp?Buddy is (awful|acceptable|awesome))/;
Run Code Online (Sandbox Code Playgroud)
这就是你得到的结果:
Compiling REx "(Regexp?Buddy is (awful|acceptable|awesome))"
Final program:
1: OPEN1 (3)
3: EXACT <Regex> (6)
6: CURLY {0,1} (10)
8: EXACT <p> (0)
10: EXACT <Buddy is > (14)
14: OPEN2 (16)
16: EXACT <a> (18)
18: TRIEC-EXACT[cw] (29) # this is a new feature in Perl 5.10
<wful>
<cceptable>
<wesome>
29: CLOSE2 (31)
31: CLOSE1 (33)
33: END (0)
anchored "Regex" at 0 floating "Buddy is a" at 5..6 (checking floating) minlen 19
Guessing start of match in sv for REx "(Regexp?Buddy is (awful|acceptable|awesome))" against 'Even if I do say so myself: "RegexBuddy is awesome"'
Found floating substr "Buddy is a" at offset 34...
Found anchored substr "Regex" at offset 29...
Starting position does not contradict # /^/m...
Guessed: match at offset 29
Matching REx "(Regexp?Buddy is (awful|acceptable|awesome))" against 'RegexBuddy is awesome"'
29 <'lf: "'> <RegexBuddy> | 1:OPEN1(3)
29 <'lf: "'> <RegexBuddy> | 3:EXACT <Regex>(6)
34 <Regex> <Buddy is a> | 6:CURLY {0,1}(10)
EXACT <p> can match 0 times out of 1...
34 <Regex> <Buddy is a> | 10: EXACT <Buddy is >(14)
43 <y is > <'awesome"'> | 14: OPEN2(16)
43 <y is > <'awesome"'> | 16: EXACT <a>(18)
44 < is a> <'wesome"'> | 18: TRIEC-EXACT[cw](29)
44 < is a> <'wesome"'> | State: 2 Accepted: 0 Charid: 2 CP: 77 After State: 3
45 < is aw> <'esome"'> | State: 3 Accepted: 0 Charid: 7 CP: 65 After State: 10
46 < is awe> <'some"'> | State: 10 Accepted: 0 Charid: b CP: 73 After State: 11
47 < is awes> <'ome"'> | State: 11 Accepted: 0 Charid: c CP: 6f After State: 12
48 < is aweso> <'me"'> | State: 12 Accepted: 0 Charid: d CP: 6d After State: 13
49 < is awesom> <'e"'> | State: 13 Accepted: 0 Charid: 7 CP: 65 After State: 14
50 < is awesome> <'"'> | State: 14 Accepted: 1 Charid: 3 CP: 0 After State: 0
got 1 possible matches
only one match left: #3 <wesome>
50 < is awesome> <'"'> | 29: CLOSE2(31)
50 < is awesome> <'"'> | 31: CLOSE1(33)
50 < is awesome> <'"'> | 33: END(0)
Match successful!
Freeing REx: "(Regexp?Buddy is (awful|acceptable|awesome))"
Run Code Online (Sandbox Code Playgroud)
(注意:我更改了输出的某些部分,以便它能更好地突出显示)
| 归档时间: |
|
| 查看次数: |
1258 次 |
| 最近记录: |