英文:
Why is git-log with perl regex negative lookbehind causing a fatal error?
问题
I cannot get git-log's regexp grep functionality to search using perl based regexp (pcre) or I can but it is not working with negative lookbehind.
git log -p -P -G'(?<!-)title'
results in output
fatal: invalid regex: Invalid preceding regular expression
However, pcre support and negative lookbehind seems to be working, if git-grep is any indicator.
E.g. git grep -P '(?<!-)title'
returns expected results.
git version 2.21.0 (Apple Git-122.2)
英文:
Either I cannot get git-log's regexp grep functionality to search using perl based regexp (pcre) or I can but it is not working with negative lookbehind.
git log -p -P -G'(?<!-)title'
results in output
fatal: invalid regex: Invalid preceding regular expression
However, pcre support and negative lookbehind seems to be working, if git-grep is any indicator.
E.g. git grep -P '(?<!-)title'
returns expected results.
git version 2.21.0 (Apple Git-122.2)
答案1
得分: 2
"-P" 不影响 "-G"。您可以通过将 "-P" 替换为 "-F"(或 --fixed-string
)来验证这一点:即使在固定字符串中没有任何查找,您仍将收到相同的错误。
"-P" 的文档中提到
将限制模式视为 Perl 兼容的正则表达式。
注意这里的 "模式" 一词。确实,--grep
选项也提到了它:
--grep=
另一方面,"-G" 没有提到:
-G
英文:
The -P
doesn't influence -G
. You can verify it by replacing -P
with -F
(or --fixed-string
): you'll still get the same error, even if there's no look-around at all in fixed strings.
The documentation of -P
says
> Consider the limiting patterns to be Perl-compatible regular expressions.
Note the word "patterns". Indeed, the --grep
options mentions it:
> --grep=<pattern>
On the other hand, -G
doesn't:
> -G<regex>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论