Subject: bug#71252: why does grep match literal newlines when there are none, even with -z?

From: Philippe Cerfon <[email-masked]>
Date: Thu, 30 May 2024 06:14:09 +0200

On Wed, May 29, 2024 at 8:09 AM Martin Schulte <[email-masked]> wrote:

> PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern.

Dammit, it's so obvious. Sorry for the noise.

Well actually, there is still one curious point left:
If these are now two patterns, than it's two times the empty pattern, right?

I recently stumbled over this in another area, and as far as I
understand POSIX does not define what should happen with BREs/EREs
that are empty (or subpatterns that are empty), but, if I remember
correctly, it's simply not part of the grammar given.

Now GNU grep says "The empty regular expression matches the empty string.".
Yet it still matches "foo" in the example above, which clearly is not empty.

So what exactly does "matches the empty string" mean? Only if the line
is completely empty (in which case I still wouldn't understand why foo
matches)? Or does it assume empty strings before/after each character?

Thanks,
Philippe