I believe that this cannot be done in one step with Notepad++. A multi-step process to copy the lines is as follows.
(1) Find the wanted pairs of lines and merge them into single lines with a marker string. (2) Bookmark all lines with the marker and copy them. (3) Paste the wanted lines into a new buffer and convert the marker strings back to newlines.
In more detail.
(Setup) Choose a marker string, something that does not occur anywhere in the buffer being searched or in the destination buffer. For this example I choose !!!
.
(1) Do a regular expression replace of ^(object.*)\R+( nat.*)$
with `\1!!!\2'. This converts the wanted lines so the first pair shown in the question become:
object network obj_any!!! nat (inside,outside) dynamic interface
(2) Open the search window and select the Mark
tab. Click on Clear all marks
, tick Bookmark line
, enter the marker string (i.e. !!!
) into the Find what
field and click on Mark all
. Select menu => Search =>
Bookmark => Copy bookmarked lines.
(3) Select the place where the copied lines should be written and Paste
in the copied lines. Do a regular expression search and replace of !!!
with \r\n\r\n
. (May need to alter the replacement string if you preferred line endings are not Windows.)
Notes
The above does not preserve the exact sequence of CRs and LFs between the two lines. The first replace uses \R+
to find any combination of CRs and LFs between the two lines. The final replace inserts a fixed CR and LF sequence.
Rather than using the Copy bookmarked lines it may be suitable to use Remove unmarked lines which then leaves only the wanted lines in the buffer. The Copy
and Paste
command are then not needed and the final search and replace can be done in the initial buffer.