Search code examples
searchreplacenotepad++

How to find lines that contain 3 specific characters?


Is there a way to remove lines that contain three specific characters?

For example the characters should be U S E

So for these lines, it should just remove USER AND UDES:

USER
USAD
UDES

Thanks


Solution

    • Ctrl+H
    • Find what: ^(?=.*U)(?=.*S)(?=.*E).+\R?
    • Replace with: LEAVE EMPTY
    • TICK Match case
    • TICK Wrap around
    • SELECT Regular expression
    • UNTICK . matches newline
    • Replace all

    Explanation:

    ^           # beginning of line
    (?=         # positive lookahead, make sure we have after:
        .*          # 0 or more any character but newline
        U           # letter uppercase U
    )           # end lookahead
    (?=.*S)     # same as above for letter S
    (?=.*E)     # same as above for letter E
    .+          # 1 or more any character but newline
    \R?         # any kind of linebreak, optional
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here