Skip to content

Commit fba4f12

Browse files
mkiedrowiczgitster
authored andcommitted
grep -P: Fix matching ^ and $
When "git grep" is run with -P/--perl-regexp, it doesn't match ^ and $ at the beginning/end of the line. This is because PCRE normally matches ^ and $ at the beginning/end of the whole text, not for each line, and "git grep" passes a large chunk of text (possibly containing many lines) to pcre_exec() and then splits the text into lines. This makes "git grep -P" behave differently from "git grep -E" and also from "grep -P" and "pcregrep": $ cat file a b $ git grep --no-index -P '^ ' file $ git grep --no-index -E '^ ' file file: b $ grep -c -P '^ ' file b $ pcregrep -c '^ ' file b Reported-by: Zbigniew Jędrzejewski-Szmek <[email protected]> Signed-off-by: Michał Kiedrowicz <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f0c5793 commit fba4f12

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)
7979
{
8080
const char *error;
8181
int erroffset;
82-
int options = 0;
82+
int options = PCRE_MULTILINE;
8383

8484
if (opt->ignore_case)
8585
options |= PCRE_CASELESS;

0 commit comments

Comments
 (0)