Search code examples
notepad++find-replace

NOTEPAD++ correcting image file path using FIND & REPLACE feature


I have thousands of html files that i need to edit to correct the image file path. I am wondering if I can add the folder name in the path using NOTEPAD++ FIND AND REPLACE feature. Anyone knows if this can be done using NOTEPAD++?

If I have this tag below and I like to add a folder name before the image filename, I like to know if we can automate notepad++ to add the folder name "images" using FIND AND REPLACE.

FROM

<img src="a002p.jpg">

RESULT I LIKE TO ACHIEVE

<img src="images/a002p.jpg">

I tried the steps as shown in the screenshot and that didn't solve the problem.

https://i.sstatic.net/636xf.jpg

notepad++ find and replace feature


Solution

    • Ctrl+H
    • Find what: "(?=\w+\.jpg")
    • Replace with: "images/
    • UNCHECK Match case
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    "           # a double quote
    (?=         # positive lookahead, make sure (but don't capture) we have after:
        \w+         # 1 or more word character (you may use .+? if you have other character than word char)
        \.jpg       # extension (you may use \.(?:jpe?g|png|gif) if you have other extensions)
    "           # a double quote
    )           # end lookahead
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here