[英]Remove all symbols, html and special chars from string
除了原始文本和单个空格之外,如何从字符串中删除所有元素? 但是,某些符号不会被删除, - , –, ’
目前我使用:
let descriptionString = description.replace(/(<([^>]+)>)/gi, "").replace(/[^a-zA-Z 0-9]+/g,"");
description
是wordpress
中的一个字段,可以包含任何内容,html、符号、编码字符等。
示例内容为:
Surgical Sim 8211 Kate O8217Connor Sim Lab
我需要移除8217
- 目前它只移除了哈希值。
我需要在react-native View
显示结果。 我不想使用WebView
来呈现html
。
有任何想法吗?
检查以下功能。 它删除了所有特殊字符、html 和符号。
function filterString(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
tmp = tmp.textContent || tmp.innerText || "";
tmp =tmp.replace(/([,"'0-9\-.~!@#$%^&*()_+=–’`{}\[\]\|\\:;"<>\/?])+/g, '').replace(/^(-)+|(-)+$/g,'');
return tmp;
}
console.log(filterString("<html>asdasjhd<body>%dasd test - , ' –, ’ ytest jsdnja @!@#@&^$@$ "));
你也可以为你的字符串测试它
console.log(filterString("Surgical Sim 8211 Kate O8217Connor Sim Lab"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.