js 获取字符串的图片路径并替换


```javascript
this.$api.appPlateForm('', 'index/goodsdetail', params, function(res) {
					if (res.code == 200) {
						let content = res.data.goods.content;
						let re = /]*src=['"]([^'"]+)[^>]*>/gi;
						let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i // 匹配图片中的src
						let reHttp = new RegExp("http");
						let imgArr = content.match(re);
						for (let i = 0; i < imgArr.length; i++) {
							let imgSrc = imgArr[i].match(srcReg);
							if (!reHttp.test(imgSrc[1])) {
								content = content.replaceAll(imgSrc[1], that.hostUrl+imgSrc[1]);
							}
						}
						that.goods_detail = content.replaceAll('

js 获取字符串的图片路径并替换_js 匹配字符串中图片路径-CSDN博客

你可能感兴趣的:(javascript,前端,java)