in reply to Growing strings in search
If one could run the match engine "backwards" and match a string in reverse, i.e., from end to beginning, that might solve your problem. Unfortunately, there's no m//r modifier that I'm aware of.
One might do a match against a reversed string:
Incrementally building and maintaining a reversed string for each "forward" string might not be too expensive even for hundreds of strings of thousands of characters. Unfortunately, you now have the problem of finding some way to persuade the "software" to generate an arbitrary regex backwards, so that, e.g., X .* Y becomes Y .* X (but that's just a small matter of programming, right? :).c:\@Work\Perl\monks>perl -wMstrict -le "my $s = ''; my $r = ''; my @add = qw(a b c X d e Y f g h); ;; my $xeger = qr{ \A Y .* X }xms; ;; while (@add){ print qq{'$s' }, $r =~ $xeger ? 'MATCH' : \"no match\"; $r = qq{$add[0]$r}; $s .= shift @add; } " '' no match 'a' no match 'ab' no match 'abc' no match 'abcX' no match 'abcXd' no match 'abcXde' no match 'abcXdeY' MATCH 'abcXdeYf' no match 'abcXdeYfg' no match
BTW: Is it possible for you to suppress re-compilation of the regex on every match, perhaps with the m//o modifier? That might speed up matching in general and at least alleviate your problem.
Give a man a fish: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Growing strings in search
by belg4mit (Prior) on Apr 20, 2020 at 13:33 UTC | |
by AnomalousMonk (Archbishop) on Apr 21, 2020 at 00:35 UTC |