Search code examples
regexnotepad++regexp-replace

NOTEPAD++ adding folder name using FIND & REPLACE feature


This is a follow-up question for my previous question that can be found in the url below:

https://stackoverflow.com/questions/66719731/

If I have the following tags below and I want to add a folder name images/ before the image file, how can i program NOTEPAD++ to add a FOLDER NAME for those A HREF tags with a JPG value. So in short I want to exclude A HREF tags with the HTM value when using the FIND & REPLACE function.

CURRENT CODE

<a href="O2A.jpg">
<a href="h025m.htm">

RESULT I LIKE TO ACHIEVE

<a href="images/O2A.jpg">
<a href="h025m.htm">

Any help you give me would be much appreciated.


Solution

  • Regex Pattern

    Here is the Regex Pattern using lookahead to find the <a href=" before a JPG file.

    \<a href=\"(?=[^\.]*\.jpg")
    

    And then, you can replace the <a href=" with

    <a href="images/
    

    The following test case passed

    <a href="O2A.jpg">
    <a href="h025m.htm">
    <a href="O55C.jpg">
    <a href="h127m.html">
    <img src="images/h001p.jpg" width="175" height="217" alt="h001p">
    

    Output

    <a href="images/O2A.jpg">
    <a href="h025m.htm">
    <a href="images/O55C.jpg">
    <a href="h127m.html">
    <img src="images/h001p.jpg" width="175" height="217" alt="h001p">