bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#16865: grep -wP and backreferences


From: Jim Meyering
Subject: bug#16865: grep -wP and backreferences
Date: Mon, 24 Feb 2014 20:55:42 -0800

On Mon, Feb 24, 2014 at 1:20 PM, Stephane Chazelas
<address@hidden> 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.
>
> Sorry I lied, it was not the last note ;-). Note the difference:
>
> $ echo a@@b | grep -w @@
> $ echo a@@b | grep -Pw @@
> a@@b
>
>
> 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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]