Update records based on regex

I need to update some records using a regex and others trigger them just if they are empty, when they are empty I have no problems but when it is a regular expression I always get an empty result but and I can’t figure out how to

The fields look like this


[caption id="" align="alignright" width="180" caption=""]<a href="http://www.medialifemagazine.com/archives/images/collegebag.gif"><img class="size-full" title="collegebag.gif" src="http://www.medialifemagazine.com/archives/images/collegebag.gif" alt="" width="180" height="259" /></a>[/caption]

and this is my regex


^\\[caption +[a-zA-Z=" 0-9\\]<>:/.-]*\\[\\/caption\\]$

Can someone help me out?

are you asking for a php solution or a mysql solution?

because mysql REGEXP can only find, not replace

no, a MySQL, I guess I was doing it wrong, I now have a regex that works

[[1]

that does find matches but I want to make sure it ends right after [/caption] but when I add $ it does not find anything

I know MySQL does not do search replace but I will be doing something like

UPDATE wp_posts SET post_content=post_content + someothefiled WHERE post_content = [[2]

I also have to read on this, I think it should be done with CONCAT but first I want to get the regex working


  1. caption .+[/caption] ↩︎

  2. caption .+[/caption] ↩︎

Okay, I think I have the concat I just need to make sure the regex works and does not modify records I don’t want it to, I will be doing something like this

UPDATE wp_posts SET post_content= concat(post_content,post_excerpt) WHERE post_content REGEXP ‘[[1]


  1. caption .+[/caption]$ ↩︎