Replace characters from certain lines



  • I want to replace > with >}} from the end of my img tags.

    Now:

    <img src="/images/example-image.png" alt="Example Image" width="244" height="110">
    

    Result:

    {{< img src="/images/example-image.png" alt="Example Image" width="244" height="110" >}}
    

    I want to change this on all pages of my website at once.

    Is it possible? If so, how?

    I already know how to change <img to {{< img. That’s the easy part.



  • @MV82

    Do both operations at once:

    find: (?-is)<img.*?>
    repl: {{$0}}
    search mode: regular expression



  • @Alan-Kilborn

    Thank you.

    But how do I get the space between {{< and img and between height="" and >}}?

    Like in the example below:

    {{< img src="/images/example-image.png" alt="Example Image" width="244" height="110" >}}
    

    I don’t know if you know how Hugo (static site generator) works, but for Hugo shortcodes, I need space between {{< and img and between height="" and >}}.

    Can you please tell me how to do that?



  • @MV82

    find: (?-is)<(img.*?)>
    repl: {{< ${1} >}}

    It might be beneficial for you to learn how this is done, for your future needs, as we don’t continually do this for repeat askers.
    See HERE to get started.



  • @Alan-Kilborn

    Thank you so much.

    This will save me a lot of time.


Log in to reply