Search code examples
regextextnotepad++

Delete odd numbered lines in text, skip blank lines


I have text of a poem that starts with the original language on odd numbered lines and a translation on even numbered lines. I want to remove the original language odd lines. I could use the Notepad++ replace function with regex ([^\n]*\n)[^\n]*\n to remove every odd numbered line but when it reaches the blank lines between paragraphs, it switches to removing the translated lines and some of the blank lines also get removed.

How would I remove the odd lines while skipping and keeping the blank lines (it doesn't have to be done in Notepad++)?


Solution

  • One option would be:

    ^.+\R(.+)
    

    See an online demo

    • ^ - Start-line anchor;
    • .+\R - Any 1+ characters upto any unicode newlince sequence;
    • (.+) - Capture a 2nd line of 1+ characters in a capture group.

    Replace with \1