【发布时间】:2017-09-28 19:14:00
【问题描述】:
在我的许多专栏中,我都有一些这样的数据:
“一些数据。[content]一些内容[/content]另一个数据”
我想删除以 [content] 开头并以 [/content] 结尾的子字符串。结果应该是:
“一些数据。另一个数据”
我知道可以将 MySQL replace() 与 Reg Ex 一起使用,但我不知道如何使用它。
任何帮助将不胜感激。
【问题讨论】:
在我的许多专栏中,我都有一些这样的数据:
“一些数据。[content]一些内容[/content]另一个数据”
我想删除以 [content] 开头并以 [/content] 结尾的子字符串。结果应该是:
“一些数据。另一个数据”
我知道可以将 MySQL replace() 与 Reg Ex 一起使用,但我不知道如何使用它。
任何帮助将不胜感激。
【问题讨论】:
首先获取所有string between该字符串,然后您可以替换它:
SELECT substring_index(substring_index(field, 'content', -1), '/content', 1) FROM table_name
运行此查询后,您会得到between string of [content] and [/content]
之后你只需要update one bye one 使用foreach loop 并使用这个query
UPDATE table_name SET field = REPLACE(field, 'content', 'content-that-will-replace-it') WHERE INSTR(field, 'content') > 0
【讨论】: