git grep -P is multiline for negative lookahead/behind

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

 



Negative lookahead/lookbehind with `git grep -P` considers the
surrounding lines of an otherwise positive match. This differs from
`grep -P` behavior. It does not repro for *positive*
lookahead/lookbehind.

Example:
$ echo -e 'Bar\nBar Baz\nBat' > test.txt && git add test.txt
$ git grep -P 'Bar(?!\sB)' test.txt  # Find 'Bar' not followed by '\sB'

With regular grep, this works:

$ grep -P 'Bar(?!\sB)' test.txt
Bar

Because \s includes \n, the negative lookahead unexpectedly finds the
B on line 2, and therefore line 1 fails to match the full expression.

Positive lookahead works like `grep -P`, in that it isn't unexpectedly
multiline:

$ git grep -P 'Bar(?=\sB)' test.txt  # Find 'Bar' followed by '\sB'
test.txt:Bar Baz
$ grep -P 'Bar(?=\sB)' test.txt
Bar Baz

Is this expected behavior, and if so, why/where is this documented?

git: git version 2.8.0.rc3.226.g39d4020, also 2.9.2.517.gf8f7adc, both
with libpcre
grep: grep (GNU grep) 2.16
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]