1
I need to replace a random text between two fixed strings in a database created by Wordpress.
Database: "database"
Table: "wordpress_posts"
Field: "post_content"
ID: "6450"
For example, I have the text <inicio do texto fixo> texto aleatório </fim do texto fixo>
, where we have "random text" I want it to be "new text", as follows:
<inicio do texto fixo> novo texto </fim do texto fixo>
I had asked a question, but it was closed because information was missing, based on a comment they left I reached the code below:
UPDATE wordpress_posts
SET post_content = REGEXP_REPLACE(
post_content, 'texto aleatório', 'novo texto')
WHERE `wordpress_posts`.`ID`='6450';
But I don’t know where to inform strings that are fixed to precisely change the text that is between them.
In accordance with the documentation, the second function parameter
REGEXP_REPLACE
accepts the pattern to be replaced. That is, you can use it for your regular expression.– Woss
@Andersoncarloswoss following the examples I left the command as follows 'UPDATE wordpress_posts SET
post_content
= REGEXP_REPLACE(post_content
, '<fixed text start>(.| n)*? </fixed text end>', 'new text') WHEREwordpress_posts
.ID
='6450'' but no effect, nothing is changed, see http://prntscr.com/ogxm7y– Wesley
changed the expression to (.| n)*? , to ensure that nothing was wrong with the typed words, but it also came to nothing http://prntscr.com/ogxmwt
– Wesley