替换字符串中图片的src
replaceImgSrc(content) console.log(replaceImgSrc(content)) function replaceImgSrc(str) { var newStr = str.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function(match, capture) { if(!/http|https/.test(capture)) { return '<img src="http://app.hsrtv.cn' + capture +'" alt="" />' } else { return '<img src="'+capture+'" alt="" />'; } }) return newStr; }