Delete an entire string from mySql table containing random characters

Philip Evers :

I'm trying to delete stings from a DB table that contain random characters ...

The string looks like this:

<h1 class="visible-xs">Chocolates</h1>

e.g.

<h1 class="visible-xs">UNKNOWN</h1>

There are thousands of entries like this but the word 'Chocolate' is different in each case.

So basically I want to delete this string from the table field ...

e.g.

UPDATE products SET products = REPLACE ( post_content, '**********', '' );

where the asterisks donate the string to be deleted.

Please help, I've searched everywhere but I'm a complete noob to this regex stuf!

GMB :

I you are running MySQL 8.0, you can use regexp_replace():

update posts
set products = regexp_replace(
    post_content, 
    '<h1 class="visible-xs">[^<]+</h1>', 
    '<h1 class="visible-xs"></h1>'
)

This assumes that the string to remove does not contain character '<'.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11473&siteId=1
Recommended