Search code examples
notepad++

Advanced find and replace in Notepad++


I'm trying to use Notepad++ for the first time and wanted to see if anyone here had some solutions for me.

I have a document that looks like this:

ex 1 
send power g1 g2 g3 g4 
ex 2 
send power g1 g2 
ex 3 
send power g1 f5 f3
ex 4 
send f5 f2 t5

... and so on, with various combinations of words after 'send'. I just need to add a line (" this is number `#'") after each 'send' line, with the # matching the 'ex #' number...so it would increase by 1 each time. The result would be:

ex 1 
send power g1 g2 g3 g4
this is number `1' 
ex 2
send power g1 g2 
this is number `2'
ex 3 
send power g1 f5 f3
this is number `3'
ex 4 
send f5 f2 t5
this is number `4'

Any advice would be greatly appreciated!


Solution

  • find:

    ex (\d+)\s+^.*$
    

    replace:

    $0\r\nthis is number `$1`
    

    searches for ex followed by a number followed by 1 or more spaces and/or line breaks followed by the entire next line

    replaces with: $0 the entire thing it found, a newline, this is number, and the number after "ex"