GNU bug report logs - #16865
grep -wP and backreferences

Previous Next

Package: grep;

Reported by: Stephane Chazelas <stephane.chazelas <at> gmail.com>

Date: Mon, 24 Feb 2014 16:31:02 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stephane Chazelas <stephane.chazelas <at> gmail.com>
To: Jim Meyering <jim <at> meyering.net>
Cc: 16865 <at> debbugs.gnu.org
Subject: bug#16865: grep -wP and backreferences
Date: Tue, 25 Feb 2014 16:08:22 +0000
[Message part 1 (text/plain, inline)]
2014-02-24 20:55:42 -0800, Jim Meyering:
> On Mon, Feb 24, 2014 at 1:20 PM, Stephane Chazelas
> <stephane.chazelas <at> gmail.com> wrote:
> > A last note: with -w, pcregrep wraps the regexp in \b...\b
> > instead of \b(?:...)\b, so it could be that those brackets are
> > not necessary in the first place.

The brackets are actually needed in cases like:

grep -Pw 'foo|bar'

(pcregrep has a bug there).


> > Maybe instead of \b(?:...)\b, we could use (?<!\w)...(?!\w)
> >
> > $ echo a%%b | grep -P '(?<!\w)%%(?!\w)'
> > $ echo %aa% | grep -P '(?<!\w)aa(?!\w)'
> > %aa%
> 
> I like both suggestions. Making -wP work like grep's -w makes perfect sense.
> Care to prepare a patch to make it do that, with a separate test case?
> "git format-patch ..." output preferred, if you're game.
> 
> I pushed the above patch, but would welcome another one.

Please find the patch attached.

(note that tests/word-delim-multibyte fails for me, but it's not
my doing, it was failing before).

-- 
Stephane
[0001-Align-grep-Pw-with-grep-w.patch (text/x-diff, attachment)]

This bug report was last modified 11 years and 90 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.