将所有以#WAV 开头的行替换为一行,notepad++

Replace all lines that start with #WAV with one single line, notepad++

我有数以千计的文件,它们都有一大块以 #WAV 开头的行。这个块可以出现在文件的任何地方,但总是一个“块”

#WAV 001.wav
#WAV "something"
#WAV 21021029910291029.ogg

这些块可能有 1000 行长,或者像上面的例子一样只有 3 行

我需要用一行替换整个块(所有以#WAV 开头的行)。

所以上面会变成

EXAMPLE REPLACEMENT

请注意,这需要适用于任何大小的块,#WAV 之后可能发生的情况是不可预测的。

使用 #WAV.* 作为正则表达式将不起作用,因为它将替换该行的所有出现,而不是整个块。

使用 #WAV(.*)#WAV 并尝试替换捕获组不会起作用,因为我无法确定捕获组的“结束”。

您可以使用以下正则表达式:

(^#WAV.*[\r\n]+)+

这将在一次选择中匹配所有以#WAV 开头的行。

使用

^#WAV\b.*(?:\R#WAV\b.*)*

参见regex proof

解释

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  #WAV                     '#WAV'
--------------------------------------------------------------------------------
  \b                       the boundary between a word char (\w) and
                           something that is not a word char
--------------------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  (?:                      group, but do not capture (0 or more times
                           (matching the most amount possible)):
--------------------------------------------------------------------------------
    \R                       line ending 
--------------------------------------------------------------------------------
    #WAV                     '#WAV'
--------------------------------------------------------------------------------
    \b                       the boundary between a word char (\w)
                             and something that is not a word char
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )*                       end of grouping