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

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

From
Junio C Hamano <gitster@pobox.com>
Date
May 3, 2023, 19:35 UTC
Message-ID
<xmqq1qjxqkbo.fsf@gitster.g>
In-Reply-To
<CAJXgQP1j6JYbtikMuWGFn44+FVb3PfmuwiFrxDGLQAYgr92Wfw@mail.gmail.com>
Kevin Ushey <kevinushey@gmail.com> writes:
Show 18 quoted lines
> 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'

Does not seem to reproduce for me. In a randomly picked repository (the source to git itself), I did

    $ cat >hello.txt
    WholeWord
    Whole Word
    Whole
    ^D

and "git grep --untracked -E '\bWhole\b' hello.txt" with or without the "-E" option shows the same two lines as hits.

Without the pathspec hello.txt, the output includes one line from unpack-trees.c as well, but the hits from the untracked hello.txt are the same.

The tip of 'master', v2.40.0, v2.38.4, v2.37.4, v2.35.4 (they are by no means significant milestones---just some random versions I picked to test) all behave the same way.

Previous: Kevin UsheyNext: Kevin Ushey
Message 2 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.