regex - 为什么带有 perl 正则表达式的 git-log 负向后查找会导致 fatal error ?

标签 regex git pcre git-log

要么我无法获得 git-log 的 regexp grep 功能来使用基于 perl 的 regexp (pcre) 进行搜索,要么我可以,但它不能与负向后查找一起工作。

git log -p -P -G'(?<!-)title'

输出结果

fatal: invalid regex: Invalid preceding regular expression

但是,如果 git-grep 是任何指标的话,PCRE 支持和负向后查找似乎有效。 例如。 git grep -P '(?<!-)title'返回预期结果。

git 版本 2.21.0 (Apple Git-122.2)

最佳答案

-P 不影响-G。您可以通过将 -P 替换为 -F (或 --fixed-string)来验证它:您仍然会收到相同的错误,即使固定字符串中根本没有环视。

-P 的文档说

Consider the limiting patterns to be Perl-compatible regular expressions.

注意“模式”这个词。事实上,--grep 选项提到了它:

--grep=<pattern>

另一方面,-G 则不会:

-G<regex>

关于regex - 为什么带有 perl 正则表达式的 git-log 负向后查找会导致 fatal error ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59608275/

相关文章:

mysql - 如何在以下查询中使用正则表达式?

regex - MS Word 中删除方括号的正则表达式

xcode - Xcode 如何与 Git 一起使用来更改分支和 check out 旧提交?

git - 使用 Git 的编码器协作最佳实践

git - pull 警告: suboptimal pack - out of memory时出错

c# - 如何在 C# 中使用 Regex 匹配给定的模式?

javascript - JS 正则表达式选择 <p></p> 内的所有 <br/> - 用于在中断后缩进文本的函数

regex - strsplit 与 gregexpr 不一致

regex - 表达式使用的特殊构造

异常日志的正则表达式