Hello @ankur-sharma, @terry-r and All,
I’m thinking about a very easy solution, with a regex S/R, which does… all the job :-))
So, let’s imagine the initial text, below :
This a some dummy text to fill up the zone line 1 line 2 insert_job:AB line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10 This a some dummy text to fill up the zone line 1 line 2 insert_job:AB line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10 This a some dummy text to fill up the zoneNow :
Open the Replace dialog ( Ctrl + H )
Select the Regular expression search mode
Tick the Wrap around option
SEARCH (?s).*?(?-s)((?:^.*\R){2}insert_job:AB\R(?:^.*\R){10})|(?s).+
REPLACE ?1\1\r\n
Clic on the Replace All buttonEt voilà !
You should get, as below, the two expected areas of text, separated with a line-break ;-))
line 1 line 2 insert_job:AB line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10 line 1 line 2 insert_job:AB line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10Notes :
The main part of this regex is (?:^.*\R){2}insert_job:AB\R(?:^.*\R){10}, which matches :
2 complete lines with their line-breaks, in a non-capturing group. So, (?:^.*\R){2}
The complete line insert_job:AB, with its like-break. So, insert_job:AB\R
10 complete lines with their line-breaks, in a non-capturing group. So, (?:^.*\R){10}
As this main part is embedded in parentheses, it’s stored as group1, for further use , in replacement
The part (?s).*?, at beginning, matches all the multi-lines stuff which precedes the main part
When no more main part can be found, the regex engine tries the second regex (?s).+, placed after the alternation symbol ( | )
This second regex matches all the remaining characters, after the last block of lines to keep till the very end of the file
Note that, if the string insert_job:AB is part of a line, you must change the part insert_job:AB\R with .*insert_job:AB.*\R
Remark : The method consists to use the following generic regex :
SEARCH (?s).*?(Your regex to match)|(?s).*
Refer to this post, for further explications :
https://notepad-plus-plus.org/community/topic/12710/marked-text-manipulation/8
Best Regards,
guy038