Remove a string that start with <div class="xxx"> and with</div> from a column in a table

2017-07-04 mysql sql

I have a table called op_description, in this table a column called description.

I want to strip HTML code from that column that start with <div class="xxx"> to the end

Answers

Can you try the below?

UPDATE op_description SET description=IF(POSITION('<div class='XXX'>' IN 
description)=0,description,CONCAT(LEFT(description,POSITION('<div 
class='XXX'>' IN description)),"</div>"));

Example:

Input:

Test <html> <div class="XXX"> Test</div>

Output:

Test <html> </div>

Related