求一个 REGEXP_REPLACE()正则替换的写法 - V2EX
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 1799 views
    This topic created in 698 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     Solana     2906 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 13:50 PVG 21:50 LAX 06:50 JFK 09:50
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86