Regex – Remove anchor tags wrapped around img tags

I’m currently working on a very large WordPress build that is heavily populated with posts. I’ve had a request come through where I have to do the following…

Remove all anchor tags that are wrapped around img tags.

Read More

For example, I need the following…

<a href="some-random-page"><img src="some-radom-image"/></a>

To become…

<img src="some-random-image"/>

Could this at all be done using an SQL update statement that I can run in phpMyAdmin as all WordPress posts are stored in the “posts” table.

Hope someone can help.

Related posts

Leave a Reply

2 comments

  1. You can do so with Dreamweaver. Export your db table. Open in Dreamweaver.

    Find the following with “regular expression” option checked.

    <a href="([^>]*)"><img src="([^>]*)"/></a>
    

    Now replace this with:

    <img src=$2/>
    

    Now import the db table back to MySQL.