Search code examples
regexnotepad++

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


I have thousands of files which all have a single chunk of lines that start with #WAV. This chunk could come anywhere in the file but is always a "chunk"

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

These chunks could be 1000 lines long or just 3 like the example above

I need to replace the entire chunk (all the lines that start with #WAV) with one single line.

So the above would just become

EXAMPLE REPLACEMENT

Note that this needs to work for any size chunk and what could come after #WAV is unpredictable.

using #WAV.* as regex wont work because it will replace all occurances of that line and not the entire chunk.

using #WAV(.*)#WAV and trying to replace the capture group wont work because I cant be sure of the "end" of the capture group.


Solution

  • You can use the following RegEx:

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

    This will match all lines starting with #WAV on a single selection.