I need to search and replace this html in a mysql database ( via phpMyAdmin ) :
<tr>
<td></td>
<td></td>
</tr>
But I don’t know how to find it, as it has line breaks.
My current query is :
UPDATE `wp_posts`
SET `post_content` = replace(post_content, '<tr>
<td></td>
<td></td>
</tr>', '')
But obviously, it’s not working.
How can I target it ?
2
Answers
If you are looking to replace a string made of 4 lines, one thing you need to be careful about is line breaks. For example in your query you have additional spaces at the beginning of lines 2, 3 and 4, that probably will not match.
Depending on your set up, line breaks could be
rn
orn
.If you are looking to replace 4 different strings, then you could either run the updates one by one, or generate a 4-level deedp nested
REPLACE()
. Here are examples for two string parts :Or :
you can use
REGEXP_REPLACE
. Please note that the provided regex both works for windows and linux style newlines. please also note that possible use of spaces are also considered in regex.n
is linux style newlinern
is windows style newlines
is space characterdb<>fiddle here