Php Script to Apply Regex Replace on MySQL Records

Use this script at your own risk. Never run scripts on your databases before backing them up!

Recently I needed to apply REGEX replacement on my posts in this blog. I wanted to remove dead links from my posts to improve my blog’s SEO. What I needed was something like MariaDB’s regex_replace, but unfortunately MySQL doesn’t have it. Apparently this capability has been demanded by MySQL users years ago but nobody cares.

regex_wallpaper-290x290

Anyways, to be able to apply regex replace on MySQL records I needed to write a PHP script and utilize preg_replace function. I am putting the source code below. You can change the parameter values and queries to fit your needs. Enjoy my little weekend project 🙂

Hope this helps.
Good Luck,
Serdar

Leave a Reply

Your email address will not be published. Required fields are marked *