GNU bug report logs -
#22655
grep-2.21 (and git master): --null-data and ranges work in an odd way (-P works fine)
Previous Next
Full log
View this message in rfc822 format
Hello,
I'm just finding out that ^ and $ no longer work with grep -Pz:
https://unix.stackexchange.com/questions/324263/grep-command-doesnt-support-and-anchors-when-its-with-pz
$ grep -Pz '^'
grep: unescaped ^ or $ not supported with -Pz
Which points to this bug.
Note that, it's not that pcre doesn't support NULL-delimited
records, it's that grep calls pcre with the wrong flag
(PCRE_MULTILINE) which is like the m flag in /.../m perl RE
operator which is explicitely to tell ^ to match at the
beginning of the subject *but also after every newline* (same
for $).
As already noted at
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=16871#8
printf 'a\nb\0' | grep -Pz '^b'
did match which was a bug indeed, but only because of that
PCRE_MULTILINE flag. If you turned off that flag:
printf 'a\nb\0' | grep -Pz '(?-m)^b'
Then it wouldn't match.
With grep 2.10:
$ printf 'a\nb\0c\0' | grep -Poz '^.'
a
b # BUG
c
$ printf 'a\nb\0c\0' | grep -Poz '(?-m)^.'
a
c
Or use \A and \z in place of ^ and $ that match at the beginning
of the subject regardless of the state of the "m" flag:
$ printf 'a\nb\0c\0' | grep -Poz '\A.'
a
c
Now with the new version, we need to use those \A, \z. Or if we
want to match at the beginning of any of the lines in a NUL
delimited record, we need ugly things like:
grep -Pz '(?:\A|(?<=\n))'
instead of
grep -Pz '(?m)^'
Can that bug please be reopened so it can be addressed
differenly (PCRE_MULTILINE removed, PCRE_DOLLAR_ENDONLY added)?
--
Stephane
This bug report was last modified 8 years and 190 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.