Search code examples
notepad++

Remove unmarked text?


How do I remove or replace unmarked text in notepad++ (anything that isn't a 4 digit number in this case)?

I've marked the numbers I want to extract by searching /d/d/d/d, but there doesn't seem to be much I can do with marked text. I can copy it, but that separates each number into a different line and I want to keep them on their original lines.

For example, I want to turn this:

John Molson, Montreal, Canada, No. 3, Lady Sherbrooke, 1817, 1818, 1825
John Molson & Sons, Montreal, Canada, 1819, 1820
Steamer Caledonia, 1817, 1818, 1820, 1822

Into this:

1817 1818 1825
1819 1820
1817 1818 1820 1822

It's seems strange to me that there aren't really any options for editing marked text. I'm not sure what the point of it is.


Solution

    • Ctrl+H
    • Find what: \d{4}(*SKIP)(*F)|.
    • Replace with: LEAVE EMPTY
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

                # a space
    \d{4}       # 4 digits
    (*SKIP)     # skip the match
    (*F)        # and say it fails
    |           # OR
    .           # any character but newline
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here