How can I delete everything from XXXX to the last line before an empty line in a text document?
Given a text document with multiple instances of the content:
XXXX
random number of lines with random text
other random text
more random text
random text
'blank line'
i want to delete everything between XXXX and the random text in the line before the blank line, and insert a comma before the random text so it looks like this:
XXXX,random text
'blank line'
How can I do this with a single command?
I currently use sublime text 3 and notepad++ on windows 10 but this question is platform agnostic. I'll use anything that works, thanks!
Assuming that "things" and "stuff" are always the same, you could use this:
Find what: XXXX\r\nthings\r\nstuff.*?\r\n(.*?)\r\n\r\n
Replace with: XXXX, \1\r\n\r\n
Where:
-
\r\n\
: stands for the Windows end-line (carriage-return, line-feed) -
.*?
: 0 or more character, non-greedy search -
()
: defines a group -
\1
: the contents of the matched group.
Here is my test-case:
And here is the result after clicking Replace All:
With Notepad:
- Find what:
XXXX\K\R(^[^'].+$\R){1,}
- Replace with:
\r\n
- Search mode: Regular Expression
Before
After