Ton Hospel wrote:
> -p0 s/\G(.*)(.* )(?=\1.\2|$)//g
> 
> This should be about as efficient as a simple regex approach gets.
> It's also the shortest yet :-) It outputs starting from the first
> line that can't be extended. No output means all lines work.

If you're free to output whatever you want on mismatch, you can also
just omit the "\G".

-p0 s/\G(.*)(.*
)(?=\1.\2|$)//g

Will print all lines that preceed invalid changes. (As requested!) One
can create files that will make some problems, though. If a line does
not add at least one character, strange things may happen. But I think
it will always output something.
And until someone proves the contrary, I consider this being the
shortest solution so far. :o)

lg,
daniel

Reply via email to