正则表达式删除具有特定符号的连续行

标签 regex notepad++

我有一个巨大的文本文件需要排序,我注意到我不需要的行通常带有连字符 - 符号并且连续超过 3 行。所以我想使用正则表达式来删除这些行。

我尝试了这个: ^.*(?:\-.*?){3}.*(?:\R|\Z) 但它仅在单行内有效,而我只需删除从 3 及以上开始的带有 - 的连续行。

我的文字示例:

Good Line 1
Error-1
Error-2:3045
Error-3-32
Good Line 2
Error-4_sub
Error-5.0
Error-6...0
Error-7
Error-8-9
Error-9
Good Line 3

期望的输出

Good Line 1
Good Line 2
Good Line 3

最佳答案

  • Ctrl+H
  • 查找内容:(?:^.*?-.*(?:\R|\z)){4,}
  • 替换为:LEAVE EMPTY
  • 检查 环绕
  • 检查 正则表达式
  • 取消选中 。匹配换行符
  • 全部替换

说明:

(?:                 # Beginning non capture group
^                   # beginning of line
  .*?               # 0 or more any character but newline, not greedy
  -                 # hyphen
  .*                # 0 or more any character but newline
  (?:\R|\z)         # non capture group, any kind of linebreak OR end of file
){4,}               # end group, must appear 4 or more times
                        # set the value to your needs

屏幕截图(之前):

enter image description here

屏幕截图(之后):

enter image description here


书签行:

enter image description here

关于正则表达式删除具有特定符号的连续行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61561884/

相关文章:

Windows 10 升级更改了我的 Notepad++ 图标

ruby - string#gsub 链的性能影响?

regex - 如何在Notepad++中将所有字符串替换为每个字符串中包含的数字?

regex - Notepad++ v4.2.2。用于匹配和替换两个标签之间所有文本的正则表达式

c# - 形成一个正则表达式来解析数值表达式

notepad++ - Notepad++ - 只保留数字

editor - Notepad++ :阻止注释不起作用

objective-c - NSString - 仅转换为纯字母表(即删除重音符号+标点符号)

regex - 如何在 Perl 正则表达式中允许文字点?

python - 使用正则表达式从python列表中删除元素