› 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 · 2153 views
    This topic created in 840 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
        1
    hwhtj  
    OP
       Jun 19, 2024
    就是把 src 后面的图片地址提取出来,前面加上![images]
    zackzergzeng
        2
    zackzergzeng  
       Jun 19, 2024
    UPDATE your_table
    SET your_column = REGEXP_REPLACE(your_column, '<img src="([^"]+)"[^>]*>', '![images]($1)')
    WHERE your_column LIKE '%<img src="%';

    chatgpt 给的答案
    xiaoluxiaolu
        3
    xiaoluxiaolu  
       Jun 19, 2024
    这最好还是别用正则做吧,用一些工具解析 html 片段然后提取里面的 src 重新组装稳定一些
    hwhtj
        4
    hwhtj  
    OP
       Jun 19, 2024
    谢谢 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
        5
    qinrui  
       Jun 19, 2024
    $(origin_str)[0].src
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2774 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 08:14 · PVG 16:14 · LAX 01:14 · JFK 04:14
    ♥ Do have faith in what you're doing.