首页 > 其他分享 >替换富文本中 img标签的src地址

替换富文本中 img标签的src地址

时间:2023-01-03 17:58:05浏览次数:36  
标签:src img capture 标签 地址 let regex3


imgSrcReplace(htmlstr) {
  let regex3 = new RegExp(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi);
  let htmlstr1 = htmlstr.replace(regex3, function(match, capture) {
    // capture 为你匹配到的地址
    // localtionPath 为你想要拼接的地址
    let newStr = '<img src=' + localtionPath + capture + ' alt="" />';
    return newStr;
  });
  regex3 = null;
  return htmlstr1;
},

标签:src,img,capture,标签,地址,let,regex3
From: https://www.cnblogs.com/rzl795/p/17023001.html

相关文章