From: Junio C Hamano Date: Sat, 05 Aug 2006 21:08:28 GMT Subject: Re: [RFC/PATCH] Fix "grep -w" Message-ID: <7vlkq2dh6b.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <118833cc0608051219q7e19800alc05870058973c2e@mail.gmail.com> "Morten Welinder" 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.