【问题标题】:is there a preg_replace for mysql or way to accomplish the same.?是否有 mysql 的 preg_replace 或完成相同操作的方法。?
【发布时间】:2020-04-23 20:37:51
【问题描述】:

我正在尝试替换列中的内容 - 例如。

UPDATE table 
SET column1 = REGEXP_REPLACE(
    column1, 
    '<span style="red">(*.)</span>', 
    '<div class="something">$1</div>'
)

我的数据库版本: $ mysql -V mysql Ver 15.1 Distrib 10.3.22-MariaDB,适用于 Linux (x86_64),使用 readline 5.1

【问题讨论】:

  • 使用preg_replace在您的PHP代码中执行此操作
  • 有 mysql 8.0.x 吗?那么是的,你可以,否则不行。
  • 你能举个例子吗?

标签: mysql sql regex mariadb


【解决方案1】:

Mariadb 有REGEXP_REPLACE 所以你这样做:

SET @a := '<span style="red">test</span>';

SELECT REGEXP_REPLACE(
    @a,
    '<span style="red">(.*)</span>',
    '<div class="something">\\1</div>'
) AS reorder_name;
|重新排序名称 | | :-------------------------------- | |
测试
|

db小提琴here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 2010-12-14
    相关资源
    最近更新 更多