On Fri, Feb 15, 2002 at 07:27:03AM -0600, Tim Ayers wrote:
> No offense, but did you try it without the comma?
Gosh, now we're getting picky! This is "fun with perl", not
"working code with perl"!
> It doesn't work. If
> you get a 2-character match, the regex engine gains a new starting
> point for the 3-character match. Thus throwing away the 2 characters
> that just matched. If they are part of the lcs, you just lost part of
> your answer.
Thanks, I got confused about where /g puts its mark. Obvious remedy
is to bump it back by hand:
while ($str =~ m{ ([^\0]{$len}) (?= [^\0]* \0 [^\0]*? \1 ) }xg) {
$len = length($match = $1) + 1;
pos($str) -= length($match);
}
On Fri, Feb 15, 2002 at 09:31:27AM -0500, Ronald J Kimball wrote:
> It does work, if you drop the comma *and* the /g modifier, so that it
> starts searching at the beginning of the string each time.
Then, I think you're back to O(N^3), which I was trying to avoid.
Andrew
PS. I guess it's somewhat amusing that trying the code didn't even
occur to me. ;)