replaceImgSrc (basePrefix, rep, questionContent) {
// console.log('old' + questionContent)
questionContent = questionContent.replace(new RegExp(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi), function (match, capture) {
if (rep) {
match = match.replace(new RegExp(capture, 'g'), basePrefix + capture)
} else {
match = match.replace(new RegExp(capture, 'g'), basePrefix + capture.slice(capture.indexOf('/', capture.indexOf('/') + 1)))
}
return match
})
// console.log('new' + questionContent)
return questionContent
}
正则替换img src
最新推荐文章于 2024-03-19 17:11:19 发布