For string processing, the databases can not perform as good as middlewares. For example, you may see every kind of regular expression related functions equipped in PHP everywhere, but you can only see two compare operators related to regular expression in MySQL.
- rlike: a synonym of regexp.
That is, there’s no built-in function of regular expression replace in MySQL, you have to create a customized function for yourself, but it may not cover all cases. Or you can switch your database to MariaDB
which is a MySQL variant and the default database of Red Hat Enterprise Linux 7, to take advantage of the built-in functions for regular expression provided by MariaDB.REGEXP_REPLACE – MariaDB Knowledge Base