FlatSpeed
FlatSpeed

Reputation: 51

Placing part of a string between brackets

I am having trouble with replacing something in a column. I have the "posts" table with the "post_text" column (MediumText).

I want to replace "EXAMPLE:https://www.youtube.com/watch?v=ICaPQLTlguM" with [block]ICaPQLTlguM[/block].

I'm Blocked at the following SQL

UPDATE post SET post_text= REPLACE('post_text','https://www.youtube.com/watch?v=','[block]');

How can i incapsulate the video referrence id in the [block][/block] brakets ?

Upvotes: 1

Views: 44

Answers (2)

M Khalid Junaid
M Khalid Junaid

Reputation: 64496

You can use concat

UPDATE post 
SET post_text=
CONCAT(
  REPLACE(post_text,'https://www.youtube.com/watch?v=','[block]')
  ,'[/block]'
);

Demo

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270873

This is more complicated than a simple replace. Perhaps you want this:

UPDATE post
    SET post_text = CONCAT('[block]',
                           substring_index(post_text, '=', -1),
                           '[/block]'
                          );

Upvotes: 1

Related Questions