开发者

Replace in mysql database

I have开发者_StackOverflow社区 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.


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 )');


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜