删除html字符串中所有空格和空标签

364 阅读1分钟
let temp = html.replaceAll('<br/>', '').replace(/\s*/g, '').replace(/&nbsp;/ig, '')

while (/<([a-z]+?)(?:\s+?[^>]*?)?>\s*?<\/\1>/ig.test(temp)) {

    temp = temp.replace(/<([a-z]+?)(?:\s+?[^>]*?)?>\s*?<\/\1>/ig, '')

}

console.log('temp', temp, temp === '')