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

Re: [RFC/PATCH] Fix "grep -w"

From
Junio C Hamano <junkio@cox.net>
Date
Aug 5, 2006, 21:08 UTC
Message-ID
<7vlkq2dh6b.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<118833cc0608051219q7e19800alc05870058973c2e@mail.gmail.com>
"Morten Welinder" <mwelinder@gmail.com> writes:
> 1. Are you sure that going to the end of the first match is correct?
> It seems to me that this will skip matches.  Say you search
> for ".*" on a line that reads
>   " xxx".

It is fine for your example, I think. .* matches the entire line the first time, and BOL and EOL are defined to be word boundaries. But you are right. If the pattern is "x xx* x" and the line is "x x xx x", the first round would match the first 5 bytes, we find that 6th byte 'x' makes it not a word boundary, and redoing the match starting at 6th is a wrong thing to do. We should find "x xx x" starting at the 3rd byte.

> 2. What about "^"?

The pattern would not match the second time anyway, so I do not think it is such a big deal.

But there is another bug I just spotted. git grep -w -e '^x' matches line "xxx" (when not cheating with external grep).

> 3. What about empty matches?  That could take a while...
True.  So we would need to make sure we advance at least one.
Previous: Morten WelinderNext: Junio C Hamano
Message 3 of 4 in “Fix "grep -w"”
  1. Fix "grep -w"Junio C Hamano, Aug 5, 2006
  2. Morten WelinderAug 5, 2006
  3. Junio C HamanoAug 5, 2006
  4. Junio C HamanoAug 6, 2006

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.