How To Replace or Delete Text Between Numbered Lines
-
I’m working on my website and I want to delete or replace text between the numbered lines in notepad++ with the replace function, is there any way an expression can be written to accomplish this? Any help would be greatly appreciated.
-
note sure I understand correctly.
Let’s say, you have some arbitrary text on lines 6 to 10
and you want to have something where you can specify 6 to 10 in find what box
and in replace with box you enter your replacement, correct? -
Correct.
-
Is there any way to write that into an expression?
-
for Delete Text Between Numbered Lines
it is based on specified text
find what :(\w-?)\w+
replace with : Emptyfor Delete Text Between word Lines
it is based on specified text
find what :(\d-?)\d+
replace with : Empty -
So, sadly, the site migration lost a reply I made to this earlier. Luckily I still had the text of most of it in an N++ tab! :)
Here’s the earlier reply again:
We can accomplish this by borrowing from the info found here.
As an example, say you want to skip 3 lines at the top of file, then replace then next 5 lines with something else. Note: Another way to say it is to replace line numbers 4 through 8.
Use this regular expression search expression to match the lines:
(?-s)(?<!\x0A)^(?:.*\R){3}\K(?:.*\R){5}
and do a Replace-All with whatever you’d like (replace with nothing to delete those lines).Note that you have to do a Replace-All and not a simple Replace due to the
\K
syntax used. For the details of why this works, see the earlier referenced link.