正则替换img标签的样式
作者:互联网
let htmlText = '<img style="border: 0px; width: 537px; display: block;">'
let str = htmlText.replace(/<img[^>]*>/gi, function (match, capture) {
return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="max-width:100%;height:auto;"') // 替换style
})
标签:style,img,标签,htmlText,replace,正则,let,替换,match 来源: https://blog.csdn.net/weixin_43099985/article/details/95647010