I have some string which I need to replace in my database using a SQL query. The string is:
[attachment=NUMBER]image.jpg[/attacment]
I want to wrap that image.jpg with an HTML image tag, but the NUMBER is screwing me up because it will be different for each string. Is there a wildcard character I can use in this query which will find any number?
Here's my search/replace query:
UPDATE `hd_posts`
SET `post_content` =
replace(post_content,
'[attachment=NUMBER]',
'<img src="http://mydomain.com/my-theme/images/')
and then...
UPDATE `hd_posts`
SET `post_content` = replace(post_content, '[/attachment]', '" />')
...so that I will end up with this:
<img src="http://mydomain.com/my-theme/images/image.jpg" />
Can anyone help? What do I use for NUMBER? I have a feeling that this is not too difficult, but I am a complete novice at this. Of course I've searched and searched, but I can't find this exact situation anywhere from which to learn. These two almost gave me what I need:
MySQL REPLACE variable string Search & replace in MySql, using regex
but not quite. I'm still confused! Thanks for any help.
If I use that first link as an example...
UPDATE `hd_posts`
SET `post_content` =
CONCAT(SUBSTRING(post_content, 1,
INSTR(post_content,'[attachment') - 1),
SUBSTRING(post_content,
INSTR(post_content, ']'),
LENGTH(post_content)
- INSTR(post_content, '[attachment'))
)
I have no idea...in that example he was trying to replace a string with '' (remove it), but I don't see how he is doing that, and I don't see how I can learn from it enough to do what I need to do.