正则表达式前瞻grep中的“未跟随" [英] Regex lookahead for 'not followed by' in grep

查看:18
本文介绍了正则表达式前瞻grep中的“未跟随"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图对 Ui. 的所有实例进行 grep,后面没有 Line 甚至只是字母 L

I am attempting to grep for all instances of Ui. not followed by Line or even just the letter L

编写正则表达式以查找特定字符串的所有实例而不是另一个字符串的正确方法是什么?

What is the proper way to write a regex for finding all instances of a particular string NOT followed by another string?

使用前瞻

grep "Ui.(?!L)" *
bash: !L: event not found


grep "Ui.(?!(Line))" *
nothing

推荐答案

负前瞻,这是您所追求的,需要比标准 grep 更强大的工具.您需要启用 PCRE 的 grep.

Negative lookahead, which is what you're after, requires a more powerful tool than the standard grep. You need a PCRE-enabled grep.

如果你有 GNU grep,当前版本支持选项 -P--perl-regexp 然后你可以使用正则表达式你想要的.

If you have GNU grep, the current version supports options -P or --perl-regexp and you can then use the regex you wanted.

如果您没有(足够新的版本)GNU grep,请考虑获取 <代码>确认.

If you don't have (a sufficiently recent version of) GNU grep, then consider getting ack.

这篇关于正则表达式前瞻grep中的“未跟随"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆