图片URL:imgs/123456.jpg
替换为:http://localhost:8080/test-imgs/
imgs/123456.jpg
示例如下:
path = ‘
http://localhost:8080/test-imgs/’;
content = ‘<p><img alt=”” src=”
imgs/123456.jpg
” style=”width: 230px; height: 345px;” /><img alt=”” src=”
imgs/123456.jpg
” style=”width: 230px; height: 243px;” /></p>’;
var imgreg = /<img.*?>/gi;
content=content.replace(imgreg,function(imgsrc){
imgsrc = imgsrc.replace(/src=(?:”\s*([^”]*)\s*”|’\s*([^’]*)\s*’|(\S+))/i,”src=\””+path+”$1\””);
return imgsrc;
});
alert(content);