Navigation

    云、贵、川、渝IT人的圈子
    • Register
    • Login
    • Search
    • 主页
    • 问答
    • 话题
    • 热门
    • 圈子
    • 招聘
    • 活动
    • 项目

    js 如何用正则匹配富文本img的src

    技术答疑
    2
    2
    9
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 一代名花
      一代名花 last edited by

      提取这一段富文本的图片路径

      2db01e4f-a11f-425e-bcb8-d334597c2e34-image.png code_text

      1 Reply Last reply Reply Quote 0
      • eijiongliu4
        eijiongliu4 last edited by

        举例:

        // 定义变量存储图片地址
        var urls = []
        // 富文本
        var content = '<p>标题,内容xxxxxx <img src="http://xxx.jpg"></p>'
        // 正则遍历匹配
        content .replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/g, function(match, capture) {
            urls.push(capture)
        })
        // 输出提取结果
        console.log(urls)
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        8
        玻
        U
        A
        大
        A
        黑
        低
        天
        白
        快
        爱
        白
        美
        此
        荒
        为
        哭
        柳
        无
        真

        社群
        昆明网页设计交流吧
        友情链接
        • Funtask
        • Funtask 社区
        • SUWIS
        • 云南北大青鸟
        ©2019-2020 滇ICP备20006698号