使用 : replace
在这里插入代码片
let html = ''
let requestURL = 'www.xxxx.com/'
let cont = '<p>阿达发大水发大水发放<img alt="" height="192" src="/upload/64a3be83df05a.jpg" style="max-width: 100%; border: 0px none;" width="115" /></p>'
let reg = new RegExp("<img [^>]*src=['\"]([^'\"]+)[^>]*>", "g");
html = cont.replace(reg, function (match, capture) {
console.log(match)
console.log(capture)
return '<img src="'+requestURL+capture+'" style="max-width:100%;height:auto;display:block;margin:0 auto" />'
});
// 返回结果:<p>阿达发大水发大水发放<img src="http://xxxx.cn/upload/64a3be83df05a.jpg" style="max-width:100%;height:auto;display:block;margin:0 auto" /></p>