Search code examples
notepad++

Replacing some text in multiple lines - Notepad++


I want to change some text but not digits

<img src=“BISM1281.png” id=“Image3” alt="">
<img src=“BISM1282.png” id=“Image3” alt="">
<img src=“BISM1283.png” id=“Image3” alt="">
to
<img src=“101BISM1281.png” id=“Image3” alt="">
<img src=“101BISM1282.png” id=“Image3” alt="">
<img src=“101BISM1283.png” id=“Image3” alt="">

I want to add some text or numbers before BISM, but don't want to change anything after BISM. Cannot use simple search and replace because “img src=“BISM” is using in different locations.


Solution

    • Ctrl+H
    • Find what: src="\K(?=BISM.+?id="Image3")
    • Replace with: 101
    • CHECK Match case
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    src="               # literally
    \K                  # forget all we have seen until this position
    (?=                 # positive lookahead, make sure we have after:
        BISM                # literally
        .+?                 # 1 or more any character but newline
        id="Image3"         # literally
    )                   # end lookahead
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here