Help for mass replacement.



  • Hello.

    I need help!

    There is a design type:

    <a href="/wp-content/uploads/2018/10/2-2.jpg"><img src="/wp-content/uploads/2018/10/2-2.jpg" alt=“Ergobag1111” width=“1000” height=“708” class=“aligncenter size-full wp-image-21814” /></a>

    <a href="/wp-content/uploads/2018/10/3-2.jpg"><img src="/wp-content/uploads/2018/10/3-2.jpg" alt=“Ergobag2222” width=“1100” height=“652” class=“aligncenter size-full wp-image-21815” /></a>

    <a href="/wp-content/uploads/2018/10/4-2.jpg"><img src="/wp-content/uploads/2018/10/4-2.jpg" alt=“Ergobag3333” width=“1200” height=“497” class=“aligncenter size-full wp-image-21816” /></a>

    We need to redo it into the next view:

    <a href="/wp-content/uploads/2018/10/2-2.jpg" class=“item” style=“background-image: url(’/wp-content/uploads/2018/10/2-2.jpg’)” data-alt=“Ergobag1111” ></a>

    <a href="/wp-content/uploads/2018/10/3-2.jpg" class=“item” style=“background-image: url(’/wp-content/uploads/2018/10/3-2.jpg’)” data-alt=“Ergobag2222” ></a>

    <a href="/wp-content/uploads/2018/10/4-2.jpg" class=“item” style=“background-image: url(’/wp-content/uploads/2018/10/4-2.jpg’)” data-alt=“Ergobag3333” ></a>

    I tried to make it a team:

    ("><img src=")|(" width="." height="." class=".* /></a>)|(" width="." height="." class=".* /></a>)

    (?1" class=“item” style=“background-image: url(’)(?2’)” data-alt=")(?3" ></a>)

    But it does not work correctly.

    I want to do exactly that the replacement occurred as a team.

    Please, help!



  • Hello, владимир-антониковn, and All,

    Assuming that your XML text uses :

    • Regular Simple quote ( ' ), of Unicode value \x{0027}, and not the characters and

    • Regular Double quote ( " ), of Unicode value \x{0022}, and not the characters and

    These changes of text can be easily done with regular expressions :-))


    • Open the Replace dialog ( Ctrl + H )

    • SEARCH ><img src="(.*?)"\x20(alt=".+?").+?\x20/(></a>)

    • REPLACE \x20class="item"\x20style="background-image:\x20url\('\1'\)"\x20data-\2\x20\3

    • Tick, preferably, the Wrap around option

    • Select the Regular expression search mode

    • Click, once on the Replace All button or several times on the Replace button

    Et voilà !

    If OK, I’ll give you some explanations on that regex S/R, next time

    Best Regards

    guy038


Log in to reply