Notepad++ 使用记事本+;基于单行文本提取特定的文本行+;

Notepad++ 使用记事本+;基于单行文本提取特定的文本行+;,notepad++,Notepad++,我在一个巨大的文本文件中有下面几行,我想提取前面的行和其他行。如果集合不包含行D,则应忽略集合 LineA LineB LineC Line1 Line2 Line3 LineD Linex LineY LineZ Line4 Line5 Line6 LineD 输出应该是 Line1 Line2 Line3 LineD Line4 Line5 Line6 LineD Ctrl+H 查找内容:(?:\A |\R\R)(?:(?!LineD)[\s\s])*?(?=\R\

我在一个巨大的文本文件中有下面几行,我想提取前面的行和其他行。如果集合不包含行D,则应忽略集合

LineA
LineB 
LineC

Line1
Line2 
Line3
LineD

Linex
LineY 
LineZ

Line4
Line5 
Line6
LineD
输出应该是

Line1
Line2 
Line3
LineD

Line4
Line5 
Line6
LineD
  • Ctrl+H
  • 查找内容:
    (?:\A |\R\R)(?:(?!LineD)[\s\s])*?(?=\R\R |\z)
  • 替换为:
    留空
  • 检查匹配案例
  • 检查环绕
  • 检查正则表达式
  • 取消选中
    。匹配换行符
  • 全部替换
说明:

(?:\A|\R\R)     # non capture group, beginning of file OR 2 linebreaks
(?:             # non capture group
  (?!LineD)     # negative lookahead, make sure sure we haven't "LineD"
  [\s\S]        # any character, including linebreak
)*?             # end group, may appear 0 or more times, not greedy
(?=\R\R|\z)     # positive lookahead, make sure we have a double linebreak OR end of file after.
屏幕截图(之前):

(?:\A|\R\R)     # non capture group, beginning of file OR 2 linebreaks
(?:             # non capture group
  (?!LineD)     # negative lookahead, make sure sure we haven't "LineD"
  [\s\S]        # any character, including linebreak
)*?             # end group, may appear 0 or more times, not greedy
(?=\R\R|\z)     # positive lookahead, make sure we have a double linebreak OR end of file after.

屏幕截图(之后):

(?:\A|\R\R)     # non capture group, beginning of file OR 2 linebreaks
(?:             # non capture group
  (?!LineD)     # negative lookahead, make sure sure we haven't "LineD"
  [\s\S]        # any character, including linebreak
)*?             # end group, may appear 0 or more times, not greedy
(?=\R\R|\z)     # positive lookahead, make sure we have a double linebreak OR end of file after.

请格式化您的问题,并向我们显示实际文本,而不是上面显示的文本。这听起来像是正则表达式的工作。