正则表达式:查找不以特定前缀开头的字符串[重复](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 answerI 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_TASKBut 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 BLAHHere'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更多推荐
发布评论