git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git grep -E doesn't accept \b word boundaries?
@ 2023-05-03 19:04 Kevin Ushey
  2023-05-03 19:35 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Ushey @ 2023-05-03 19:04 UTC (permalink / raw)
  To: git

Hello,

I'm seeing the following, which I believe is unexpected. I have a file
with contents:

$ cat hello.txt
WholeWord
Whole Word
Whole

I can use `git grep` to search with word boundaries; e.g.

$ git grep --untracked '\bWhole\b'
hello.txt:Whole Word
hello.txt:Whole

However, if I add `-E` to use extended regular expressions, the same
invocation finds no search results.

$ git grep --untracked -E '\bWhole\b'

This does seem to work as expected with the '-w' flag, e.g.

$ git grep --untracked -E -w 'Whole'
hello.txt:Whole Word
hello.txt:Whole

as well as with POSIX word boundaries, e.g.

$ git grep --untracked -E '[[:<:]]Whole[[:>:]]'
hello.txt:Whole Word
hello.txt:Whole

Is this a bug, or am I misunderstanding some behavior in `git grep`?
For posterity:

$ git grep --untracked -G '\bWhole\b'
hello.txt:Whole Word
hello.txt:Whole

$ git grep --untracked -E '\bWhole\b'

$ git grep --untracked -P '\bWhole\b'
hello.txt:Whole Word
hello.txt:Whole

For what it's worth, I don't see this issue with an older version of
`git` on an Ubuntu 22.04 VM:

root@96722b73f316:~/test# git --version
git version 2.34.1
root@96722b73f316:~/test# git grep --untracked -E '\bWhole\b'
hello.txt:Whole Word
hello.txt:Whole

Thanks,
Kevin

------

[System Info]
git version:
git version 2.40.1
cpu: arm64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28
PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64
compiler info: clang: 14.0.3 (clang-1403.0.22.14.1)
libc info: no libc information available
$SHELL (typically, interactive shell): /opt/homebrew/bin/bash

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-03 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-03 19:04 git grep -E doesn't accept \b word boundaries? Kevin Ushey
2023-05-03 19:35 ` Junio C Hamano
2023-05-03 20:32   ` Kevin Ushey
2023-05-03 20:45     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).