› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
hwhtj
V2EX  ›  MySQL

求一个 REGEXP_REPLACE()正则替换的写法

  •  
  •   hwhtj ·
    sometech · Jun 19, 2024 · 2253 views
    This topic created in 867 days ago, the information mentioned may be changed or developed.
    原文是这样的
    <img src="https://www.baidu.com/images/123abc.jpg" width="700" height="467" alt="" />
    替换成下面这样的

    ![images]( https://www.baidu.com/images/123abc.jpg)
    5 replies  •  2024-06-19 16:50:41 +08:00
    hwhtj
    hwhtj
    OP
    Jun 19, 2024
    1
    就是把 src 后面的图片地址提取出来,前面加上![images]
    zackzergzeng
    zackzergzeng
    Jun 19, 2024
    2
    UPDATE your_table
    SET your_column = REGEXP_REPLACE(your_column, '<img src="([^"]+)"[^>]*>', '![images]($1)')
    WHERE your_column LIKE '%<img src="%';

    chatgpt 给的答案
    xiaoluxiaolu
    xiaoluxiaolu
    Jun 19, 2024
    3
    这最好还是别用正则做吧,用一些工具解析 html 片段然后提取里面的 src 重新组装稳定一些
    hwhtj
    hwhtj
    OP
    Jun 19, 2024
    4
    谢谢 zackzergzeng ,还有这样的
    原文
    <img style="width: 606px; height: 476px;" src=" https://www.baidu.com/images/123abc.jpg" alt="" />
    同样替换成下面这样的

    ![images]( https://www.baidu.com/images/123abc.jpg)
    就是把 src 后面的图片地址提取出来,前面加上![images]
    qinrui
    qinrui
    Jun 19, 2024
    5
    $(origin_str)[0].src
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3157 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 100ms · UTC 04:33 · PVG 12:33 · LAX 20:33 · JFK 23:33
    ♥ Do have faith in what you're doing.