1

I have a string like this in my column:

<p>[img ret872154ftu] fileaddress [/img ret872154ftu]</p>
<p>[img fd68721cvn] fileaddress [/img fd68721cvn]</p>
<p>[img xdfh654t] fileaddress [/img xdfh654t]</p>

Now i wish to remove unwanted chars inside [img] and [/img]. I have already used this query but does not work:

UPDATE `table` SET `content` = replace(`content`, '[img [^]*]', '[img]');

Any suggestion?

1
  • 1
    REPLACE doesn't take a regular expression, and there is not a native mysql function for regex replacing, only comparing. Commented Jan 1, 2014 at 19:39

1 Answer 1

3
UPDATE table SET
 column=REPLACE(column,SUBSTRING_INDEX(SUBSTRING_INDEX(column,'/img ',-1),']',1),'');

UPDATE table SET
 column=REPLACE(column,SUBSTRING_INDEX(SUBSTRING_INDEX(column,'[img ',-1),']',1),'');

SQL Fiddle

2 updates,with different delimiters because the texts might be different.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.