Search code examples
notepad++

Get all searched strings only


I have a big file with long lines. I want to get the values matching my regex only.

My line:

XXXXXXXXXXXXXX;XXXXXXXXXXXX;XXXXXXXXXXXXXXXXX;666=0;XXXXXXXXXXXXXX;XXXXXXXXXX;XXX

I need to get only the value right after 665 in all lines. example: ;665=.;

so results should look like:

;665=1;
;665=5;
;665=B;
;665=AB;

And not the whole lines. The reason is that the result is always truncated in the search window


Solution

    • Ctrl+H
    • Find what: ^.+(;666=[^;\r\n]+;).+$
    • Replace with: $1
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    ^           # beginning of line
        .+          # 1 or more any character but newline
        (           # group 1
            ;666=       # literally
            [^;\r\n]+   # 1 or more non semicolon and non linebreak
            ;           # a semicolon
        )           # end group
        .+          # 1 or more any character but newline
    $           # end of line
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here