移除的 html 的所有空标签及内容

85 阅读1分钟
// 移除的 html 的所有空标签及内容

export const removeHtmlTagsAndContent = (str: string): string => {

let tempHtml = str

.replace(/\s*/g, '')

.replace(/ /gi, '')

.replace(/<br\s*\/?>/gi, '')

.replace(/<p\s*\/?>/gi, '')

.replace(/<\/p\s*\/?>/gi, '')

.replace(/(<([^>]+)>)/gi, '')

.replace(/\n/gi, '');

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

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

}

return tempHtml;

};