Notepad ++:删除包含单词“Correct”及其上方两行的行

时间:2015-06-29 14:31:43

标签: regex replace notepad++ text-files

我有一个这样的文本文件:

010 2015.06.29 09:57:57.731 WARN  ALWAYS_SAME_TEXT] No notaris found with the given strings (used postadres): DIFFERENT_TEXTS
010 2015.06.29 09:57:58.220 WARN  ALWAYS_SAME_TEXT] No tussenpersoon found with the given strings: DIFFERENT_TEXTS
010 2015.06.29 09:57:59.288 WARN  ALWAYS_SAME_TEXT] More than one cluster (2) found with the given string: DIFFERENT_TEXTS
010 2015.06.29 09:58:00.192 WARN  ALWAYS_SAME_TEXT] More than one cluster (2) found with the given string: DIFFERENT_TEXTS
010 2015.06.29 09:58:02.766 WARN  ALWAYS_SAME_TEXT] No notaris found with the given strings (used bezoekadres): DIFFERENT_TEXTS
Trying to retrieve notaris with postadres instead of bezoekadres
010 2015.06.29 09:58:02.778 WARN  ALWAYS_SAME_TEXT] Correct notaris is found when using the postadres instead of bezoekadres
010 2015.06.29 09:58:03.647 WARN  ALWAYS_SAME_TEXT] No notaris found with the given strings (used bezoekadres): DIFFERENT_TEXTS
Trying to retrieve notaris with postadres instead of bezoekadres
010 2015.06.29 09:58:03.659 WARN  ALWAYS_SAME_TEXT] Correct notaris is found when using the postadres instead of bezoekadres
010 2015.06.29 09:58:03.991 WARN  ALWAYS_SAME_TEXT] No notaris found with the given strings (used bezoekadres): DIFFERENT_TEXTS
Trying to retrieve notaris with postadres instead of bezoekadres
010 2015.06.29 09:58:04.004 WARN  ALWAYS_SAME_TEXT] No notaris found with the given strings (used postadres): DIFFERENT_TEXTS

我想要实现的是删除以下所有行(包含“正确”一词):

Correct notaris is found when using the postadres instead of bezoekadres

包括它上面的两行。所以在上面的例子中,我想删除以下行:

010 2015.06.29 09:58:02.766 WARN  ALWAYS_SAME_TEXT] No notaris found with the given strings (used bezoekadres): DIFFERENT_TEXTS
Trying to retrieve notaris with postadres instead of bezoekadres
010 2015.06.29 09:58:02.778 WARN  ALWAYS_SAME_TEXT] Correct notaris is found when using the postadres instead of bezoekadres
010 2015.06.29 09:58:03.647 WARN  ALWAYS_SAME_TEXT] No notaris found with the given strings (used bezoekadres): DIFFERENT_TEXTS
Trying to retrieve notaris with postadres instead of bezoekadres
010 2015.06.29 09:58:03.659 WARN  ALWAYS_SAME_TEXT] Correct notaris is found when using the postadres instead of bezoekadres
  • 注意:替换ALWAYS_SAME_TEXTDIFFERENT_TEXTS 保密。如名称所述,ALWAYS_SAME_TEXT是 始终是同一段文字,DIFFERENT_TEXTS有 每个日志行不同的文本。

我知道我可以使用Ctrl + F - > Mark-tab - > Bookmark line checkbox - > Mark all带有搜索字词Correct,但如果在Notepad ++中甚至可以这样,我怎样才能在包含单词"Correct"的行上方标记所有两行。有太多的东西要手工标记。

实际上,我问的是错误的问题,让我再试一次:

我有一个.txt文件,其中包含上述示例中的日志行,并希望删除包含单词Correct的所有行以及该行上方的每两行。我更喜欢在Notepad ++中执行此操作,但如果有人有一个简单的复制粘贴文件,我可以在Visual Studio中运行以实现相同的目标,我也可以。

1 个答案:

答案 0 :(得分:1)

正则表达式:

.*[\r\n]+.*[\r\n]+.*\bCorrect\b.*[\r\n]*

替换字符串:

empty string