in reply to Can I determine index point of failure in string during regex match attempt
If $r is really just a plain, simple string of characters, it seems to me you're asking questions that can easily be answered by index. If $r is a regex of limitless complexity, it seems much more difficult, perhaps impossible, to answer the question "could there be a match if more characters were added to the right end of $s?"
Updates:c:\@Work\Perl>perl -wMstrict -le "my $r = '123'; ;; for my $s ('', qw(1 12 123 1234 2 23 234)) { my $left_same = 0 == index($r, $s); my $all_same = $r eq $s; printf qq{%-6s with more stuff could %smatch with '$r' \n}, qq{'$s'}, ($left_same and not $all_same) ? '' : 'NOT ' ; } " '' with more stuff could match with '123' '1' with more stuff could match with '123' '12' with more stuff could match with '123' '123' with more stuff could NOT match with '123' '1234' with more stuff could NOT match with '123' '2' with more stuff could NOT match with '123' '23' with more stuff could NOT match with '123' '234' with more stuff could NOT match with '123'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can I determine index point of failure in string during regex match attempt
by tj_thompson (Monk) on May 06, 2014 at 23:52 UTC | |
by AnomalousMonk (Archbishop) on May 07, 2014 at 00:53 UTC |