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

时间:2016-11-02 17:32:52

标签: regex

我正在寻找日志文件中的更改。 这是一个例子:

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

我已经知道我改变了Class1和Class2。所以我需要找到我改变的另一个类(本例中为SecondClass)

如何创建正则表达式以排除Class1和Class2? 我在Sublime Text中使用搜索

我已经尝试过: Regular expression to match a line that doesn't contain a word? 结果:enter image description here

RegEx to exclude a specific string constant 结果: enter image description here

1 个答案:

答案 0 :(得分:2)

您似乎需要将一些未跟随数字的字符串(您将在每次匹配后手动添加)匹配为整个单词

您可以使用带有替代组(...|...|etc.)和字边界\b的基于正面的负面前瞻:

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

如果已知部分跟随12312等,后跟字边界(请参阅(123|12|1|2|3)\b),则否定前瞻会使匹配失败。捕获组可以用仅用于分组的非捕获组替换:(123|12|1|2|3) => (?:123|12|1|2|3)(意味着它不会将任何子文本放入$1,第1组)。