Perhaps RegexCoach offers what you're looking for...
views:
171answers:
4That's probably so because it should not matter how the regex engine finds a match. The screenshot of RegexBuddy makes me want to use another regexp matcher, as there should not be a need to do backtracking.
Normally, you would translate the regular expression into an nondeterministic finite automaton (NFA) or a deterministic finite automaton (DFA), which can handle regular expressions without backtracking.
That being said, the only free tool for creating and testing regular expressions I know of is pyreb.
It's not quite as powerful as RegexBuddy, but it's a simple online interface: http://www.gskinner.com/RegExr/
You can mouse-over parts of your expression and it will tell you what it's doing. Very basic, but it can really save time when you do something stupid.
In Perl you can always just use re 'debug';
or use re 'debugcolor';
For example if you enter this into 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))/;
This is what you get out:
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))"
( Note: I changed some parts of the output, so that it would highlight better )