正则去除html字符串中的注释、标签、属性

var str = '<!-- 注释1 --><h1 style="color:#00ff00;text-align: center;">ProsperLee<!-- 注释 --></h1>';
        document.write(str.replace(/<!--[wW
]*?-->/gmi, '')); // 去除HTML中的注释
        document.write(str.replace(/<[^>]+>/g,"")); // 去除HTML标签
        document.write(str.replace(/(<[^s/>]+)[^>]*>/gi,"$1>")); // 去除HTML标签中的属性
原文地址:https://www.cnblogs.com/my-577/p/9767922.html