【问题标题】:Replace Content using MySQL使用 MySQL 替换内容
【发布时间】:2017-09-28 19:14:00
【问题描述】:

在我的许多专栏中,我都有一些这样的数据:

“一些数据。[content]一些内容[/content]另一个数据”

我想删除以 [content] 开头并以 [/content] 结尾的子字符串。结果应该是:

“一些数据。另一个数据”

我知道可以将 MySQL replace() 与 Reg Ex 一起使用,但我不知道如何使用它。

任何帮助将不胜感激。

【问题讨论】:

    标签: mysql regex


    【解决方案1】:

    首先获取所有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

    【讨论】:

    • 我不想只用“内容”部分替换它。我想用“[content]Some Content[/content]”替换它。
    • @感谢您的快速回复。请您提供我提供的数据的整个查询,因为我没有得到它?
    • 我不仅想要内容标签之间的字符串,还想要内容标签。
    猜你喜欢
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 2011-01-30
    • 2020-07-11
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    相关资源
    最近更新 更多