git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git grep -E doesn't accept \b word boundaries?

From
KUKevin Ushey <kevinushey@gmail.com>
Date
May 3, 2023, 19:04 UTC
Message-ID
<CAJXgQP1j6JYbtikMuWGFn44+FVb3PfmuwiFrxDGLQAYgr92Wfw@mail.gmail.com>
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

Next: Junio C Hamano
Message 1 of 4 in “git grep -E doesn't accept \b word boundaries?”
  1. Kevin UsheyMay 3, 2023
  2. Junio C HamanoMay 3, 2023
  3. Kevin UsheyMay 3, 2023
  4. Junio C HamanoMay 3, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.