虽然有许多优秀的在线和离线工具可用于测试正则表达式,但我还没有找到一个工具(除RegexBuddy之外),它可以让我看到正则表达式引擎找到匹配项所需的步骤(或发现没有匹配,就此而言。)
有谁知道这样做的任何工具?我最初排除RegexBuddy的原因是因为它是商业广告,我宁愿在我决定支付之前查看我的选项。
为了让我更清楚我想要的,这里是RegexBuddy(来自他们的主页)的截图: http://img166.imageshack.us/img166/1272/debug.png
答案 0 :(得分:4)
在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))/;
这就是你得到的结果:
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))"
(注意:我更改了输出的某些部分,以便更好地突出显示)
答案 1 :(得分:2)
它不如RegexBuddy强大,但它是一个简单的在线界面:http://www.gskinner.com/RegExr/
您可以将鼠标悬停在表达式的某些部分,它会告诉您它正在做什么。非常基本,但是当你做一些愚蠢的事情时,它确实可以节省时间。
答案 2 :(得分:1)
也许RegexCoach提供您正在寻找的东西......
答案 3 :(得分:1)
答案 4 :(得分:0)
尝试使用CodVerter regex tester在线正则表达式测试器来验证正则表达式模式。
编辑器正在更新,同时键入,并且可以根据需要更改标志。
可以将工作保存到本地或云中,以通过用户帐户中的高级存储库管理器进行进一步编辑。保存到云中时,您可以生成一个链接以与任何人共享您的工作。
CodVerter regex测试器中的如果您需要用于多种正则表达式模式的更高级工具,请尝试CodVerter multiple regex patterns scanner
以下是关于此工具的简短tutorial
(完全公开:我是CodVerter的开发人员之一)
答案 5 :(得分:-1)
这可能是因为正则表达式引擎如何找到匹配并不重要。 RegexBuddy的屏幕截图让我想要使用另一个正则表达式匹配器,因为不需要进行回溯。
通常情况下,您可以将正则表达式转换为nondeterministic finite automaton (NFA)或deterministic finite automaton (DFA),它可以处理正则表达式而无需回溯。
话虽这么说,创建和测试我所知道的正则表达式的唯一免费工具是pyreb。