Discussion › Forums › discussion › How to replace delete whole line containing specific characters?
This topic contains 0 voices and has 4 replies.
| Author | Posts |
|---|---|
| Author | Posts |
| May 29, 2008 at 7:56 pm #408 | |
|
horus Member
|
Suppose I want to delete all those whole lines containing the characters “abc”. By whole line, I mean even the newline character. If I use the regex ^.*abc.*$ and replace it with nothing, empty lines will be left. But I don’t even want empty lines. What should I do? |
| May 30, 2008 at 12:23 pm #15907 | |
|
horus Member
|
I’ve found an alternative solution: 1. replacing those lines with blank lines 2. replacing double blank lines with single blank line For 2., I’d like to replace multiple blank lines with one single blank line, but I don’t see how. I’ve tried (rn)+rn but this isn’t possible. Too bad. |
| May 30, 2008 at 2:00 pm #15908 | |
|
simon Key Master
|
That’s a pretty good workaround, this will all be solved once the multi-line regular expression support is done (which will be in for the next stable release). Basically, do your regex replace to get the blank lines. Switch to the backslash expressions mode and do the following Replace All until no matches are found: Find Text: Replace With: It shouldn’t take too many presses of Replace All to get you there. You could even script this with PyPN. |
| June 21, 2008 at 4:26 pm #15909 | |
|
kuukkeli Member
|
I was trying to find out something to do when I saw this. Here’s a small PyPN script that removes all lines that include the text in current selection (I couldn’t figure out a way to read the contents of a search field):
|
| June 22, 2008 at 12:25 am #15910 | |
|
kuukkeli Member
|
Does the edit button disappear after a while? Anyways, I forgot to include imports on that previous code so I’ll just post it again in a “standalone” form.
|
You must be logged in to reply to this topic.