1.直接替换
str.replace(/(<img [^>]*src=['"])([^'"]+)([^>]*>)/g, `$1${serverApi}$2/$3`)
2.只替换没有http的
str.replace( /(<img[^>]*src=['"])(?:(?!(https|http)))([^>]*>)/g, `$1${serverApi}$2/$3`)
1.直接替换
str.replace(/(<img [^>]*src=['"])([^'"]+)([^>]*>)/g, `$1${serverApi}$2/$3`)
2.只替换没有http的
str.replace( /(<img[^>]*src=['"])(?:(?!(https|http)))([^>]*>)/g, `$1${serverApi}$2/$3`)
本文标题:js正则替换image相对路径为绝对路径
本文链接:https://www.haomeiwen.com/subject/mnddehtx.html
网友评论