1、remove the tag of html
testString.replace(/<[^>]+>/g, '')
2、replace the tag of br [<br/>] with \n
testString.replace(/(\<br \/\>)/g, '\n')
3、find the img
const matchReg = /<img.*?(?:>|\/>)/gi
const result = data.match(matchReg)
const imageArr = []
if (result !== null && result.length > 0) {
result.map((item, index) => {
const src = item.match(/src=[\'\"]?([^\'\"]*)[\'\"]?/i)
data = data.replace(item, '\n【picture' + (index + 1) + '】\n') // replace the img with some text like image xxx, usually used like rich-text in excel
imageArr.push(src[1])
})
}
发表评论 取消回复