获得支持负向后查找的 GNU grep 等价物的最简单方法是什么?

发布于 2024-08-26 18:29:34 字数 367 浏览 4 评论 0原文

我正在尝试 grep 遍历嵌套子目录中的一堆文件来查找正则表达式匹配;我的正则表达式需要负向后查找。

Perl 具有负向后查找功能,但据我所知 GNU grep 不支持负向后查找

获得支持负向后查找的 GNU grep 等价物的最简单方法是什么?

(我想我可以用 Perl 编写自己的迷你 grep,但这似乎没有必要。我的 Perl Cookbook 副本包括 tcgrep 的源代码;这是我应该使用的吗?如果是,最新的在哪里版本?别告诉我我必须输入整个程序!)

I'm trying to grep through a bunch of files in nested subdirectories to look for regular expression matches; my regex requires negative lookbehind.

Perl has negative lookbehind, but as far as I can tell GNU grep doesn't support negative lookbehinds.

What's the easiest way to get an equivalent to GNU grep that supports negative lookbehinds?

(I guess I could write my own mini-grep in Perl, but that doesn't seem like it should be necessary. My copy of the Perl Cookbook includes source for tcgrep; is that what I should use? If so, where's the latest version? Don't tell me I have to type this entire program!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿哥们儿 2024-09-02 18:29:34

使用ack! Ack 是用 Perl 编写的,因此它使用 Perl 的正则表达式引擎(默认情况下)。

消极的后视是ack“(?(根据willert的评论)

Use ack! Ack is written in Perl so it uses Perl's regex engine (by default).

The negative look-behind is ack "(?<!bad)boy" (per willert's comment)

旧话新听 2024-09-02 18:29:34

感谢其他问题的评论。我发现在 grep 中使用 -P/--perl-regexp 选项实验性地支持负向后查找,因此您可能仍然不需要使用不同的工具,如果您更喜欢继续使用 grep

顺便说一句,我首选的 grep 替代方案是 grin (用 python 编写)。

Thanks to a comment from other question. I've found that negative lookbehind is experimentally supported in grep with the -P/--perl-regexp option, so you may still not need to use a different tool if you prefer to keep using grep.

By the way, my preferred alternative to grep is grin (which is written in python).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文