in reply to Split a sentence into words
Here is a dumb, straightforward approach:
That displays a rather disappointing yet for a start, encouraging result:# your data my @vocabulary = qw(a abc abcd abd bc); my $sentence = 'abdaabc'; # regex for words my $re = join '|', @vocabulary; # does it match in *any* way my $success = $sentence =~ /^(?:$re)*$/; # show result print $success || 0;
Okay, so it matches, but we have no idea how. We should find a way to mark where it matches, and where it backtracks.1
But after that, I'm lost. I've tried (??{code()) in various combinations, trying to capture intermediate state of the regex, including $^R, pos, @- and @+, but I don't get any intuitive results... maybe somebody else can take it up from here?
The only other thing that yields interesting results, is
but it's not something you can use in a script.use re 'debug';
|
|---|