简体   繁体   English

正则表达式 - 排除搜索结果

[英]Regex - exclude search results

I am looking for my changes in log file.我在日志文件中查找我的更改。 Here is example:这是示例:

"2-11-2016 11:39:27 CET","somemail@gmail.com","Changed Class1 Apex Class code","Apex Class",""
"2-11-2016 12:39:27 CET","somemail@gmail.com","Changed Class2 Apex Class code","Apex Class",""
"2-11-2016 13:39:27 CET","somemail@gmail.com","Changed Class2 Apex Class code","Apex Class",""
"2-11-2016 14:39:27 CET","somemail@gmail.com","Changed Class1 Apex Class code","Apex Class",""
"2-11-2016 15:39:27 CET","somemail@gmail.com","Changed Class3 Apex Class code","Apex Class",""
...
"2-11-2016 15:39:27 CET","somemail@gmail.com","Changed FirstClass Apex Class code","Apex Class",""
"2-11-2016 15:39:27 CET","somemail@gmail.com","Changed SecondClass Apex Class code","Apex Class",""

I already know that I changed Class1 and Class2.我已经知道我更改了 Class1 和 Class2。 So I need to find another classes that I changed (SecondClass in this example)所以我需要找到我改变的另一个类(在这个例子中是SecondClass)

how to create regex to exclude Class1 and Class2?如何创建正则表达式以排除 Class1 和 Class2? I use search in Sublime Text我在 Sublime Text 中使用搜索

It appears you need to match some string that is not followed with a number (that you are going to add manually after each match) as a whole word .看来您需要匹配一些后面没有数字的字符串(您将在每次匹配后手动添加)作为一个完整的单词

You may use a negative lookahead based regex with a group of alternatives (...|...|etc.) and a word boundary \\b :您可以将基于负前瞻的正则表达式与一组替代项(...|...|etc.)和单词边界\\b

"somemail@gmail.com","Changed Class(?!(123|12|1|2|3)\b)
|
---------- a known part --------------------|negative lookahead|

The negative lookahead fails the match if the known part is followed with 123 , or 12 , etc. followed with a word boundary (see (123|12|1|2|3)\\b ).如果已知部分后跟12312等后跟单词边界(请参阅(123|12|1|2|3)\\b ),则负向先行匹配失败。 The capturing group can be replaced with a non-capturing one that is only used for grouping: (123|12|1|2|3) => (?:123|12|1|2|3) (meaning it won't put any subtext into $1 , Group 1).捕获组可以替换为仅用于分组的非捕获组: (123|12|1|2|3) => (?:123|12|1|2|3) (意味着它不会t 将任何潜台词放入$1 ,第 1 组)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM