path: root/grep.c
diff options
authorMichał Kiedrowicz <>2012-02-25 09:24:28 (GMT)
committerJunio C Hamano <>2012-02-27 00:34:03 (GMT)
commitfba4f1259db8e5dc47b1c8e6e344c61f7eb4a9df (patch)
tree29d7fee27130fd8acf264055f850ff4641e9a150 /grep.c
parentf0c5793b37a53992611968ab4a1d62a0e3edc2dd (diff)
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 <> Signed-off-by: Michał Kiedrowicz <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'grep.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/grep.c b/grep.c
index b29d09c..9c5e1cd 100644
--- a/grep.c
+++ b/grep.c
@@ -79,7 +79,7 @@ static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)
const char *error;
int erroffset;
- int options = 0;
+ int options = PCRE_MULTILINE;
if (opt->ignore_case)
options |= PCRE_CASELESS;