2

I have a question about replacement a particular string in mysql but one part of the string is is changed every time e.g

"(my string to replace 1224:2)"
"(my string to replace 134:4)"
"(my string to replace 1824:9)"
"(my string to replace 14:2)"

I can change first part of string using this query

update dle_post set short_story = replace(short_story,'(my','( my');

but how to replace other parts like 1224:2) , or 14:2) or any other part that ends with a number 1,2,3.. and a ). I can not use bracket ")" because it is used on many other places.

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
Hafiz
  • 43
  • 4

2 Answers2

1

Not the most elegant way, but...

update dle_post 
set short_story = 
    replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
    short_story,
    '0)','0 )'),'1)','1 )'),'2)','2 )'),'3)','3 )'),'4)','4 )'),'5)','5 )'),'6)','6 )'),'7)','7 )'),'8)','8 )'),'9)','9 )');
Karolis
  • 9,396
  • 29
  • 38
0

Regular expressions should work in this kind of case. Take a look related question: How to do a regular expression replace in MySQL?

Community
  • 1
  • 1
Petteri H
  • 11,779
  • 12
  • 64
  • 94