正则表达式:查找不以特定前缀开头的字符串[重复](regex: find strings that do not begin with a certain prefix [duplicate])

编程入门 行业动态 更新时间:2024-10-08 06:28:14
正则表达式:查找不以特定前缀开头的字符串[重复](regex: find strings that do not begin with a certain prefix [duplicate])

这个问题在这里已有答案:

不以序列 1答案 开头的字符串的正则表达式

我想在字符串中找到一个单词,但前提是它不以前缀开头

例如。

我想找到APP_PERFORM_TASK的所有外观,但前提是它们没有以CMD_DO的前缀开头(“

所以,

CMD_DO("APP_PERFORM_TASK") <- OK (i don't need to know about this) BLAH("APP_PERFORM_TASK") <-- NOT OK, this should match my search.

我试过了:

(?!CMD_DO\(")APP_PERFORM_TASK

但这并不能产生我需要的结果。 我做错了什么?

This question already has an answer here:

Regular expression for a string that does not start with a sequence 1 answer

I want to find a word in strings, but only if it doesn't begin with a prefix.

for example.

I'd like to find all the appearances of APP_PERFORM_TASK, but only if they are not starting with a prefix of CMD_DO("

so,

CMD_DO("APP_PERFORM_TASK") <- OK (i don't need to know about this) BLAH("APP_PERFORM_TASK") <-- NOT OK, this should match my search.

I tried:

(?!CMD_DO\(")APP_PERFORM_TASK

But that doesn't produce the results I need. What I doing wrong?

最满意答案

这是一个快速的方法:

使用--invert-match(也称为-v)标志来忽略CMD_DO并将结果传递给仅与BLAH匹配的第二个grep:

grep -v CMD_DO dummy | grep BLAH

Here's a quick way:

Use the --invert-match (also known as -v) flag to ignore CMD_DO and pipe the results to a second grep that only matches BLAH:

grep -v CMD_DO dummy | grep BLAH

更多推荐

本文发布于:2023-07-17 10:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:前缀   字符串   不以   开头   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!