How to remove html tags from string

How to remove html tags from string

1.Remove html tags

filterHtmlTag(str = ""){
	let content = str.replace(/<\/?[^>]*>/g,"");//去除标签
	content = content .replace(/[|]*\n/,"");//去除行尾空格
	return content;
}

2. Remove labels and add special treatment

filterHtmlTagSpecil(str = ""){
	let content = str.replace(/<\/?[^>]*>/g,"");//去除标签
	content = content .replace(/[|]*\n/,"");//去除行尾空格
	content = content.replace(/&nbsp;/ig,""); //去除&nbsp;
	return content;
}

3. Remove the tag and keep the br tag

filterHtmlTagRetainBar(str = ""){
	let content = str.replace(/<(?!\/?br\/?.+?>)[^<>]*>/g,"");//去除标签
	return content;
}

4. Remove tags and keep img

filterHtmlTagRetainImg(str = ""){
	let content = str.replace(/<\/?((?!img).)*?\/?>/g,"");//去除标签
	return content;
}

Guess you like

Origin blog.csdn.net/qq_36893477/article/details/108446860