Javascript RegEx替换html实体

Javascript RegEx替换html实体,javascript,html,regex,Javascript,Html,Regex,全部。我正在寻找一种方法来替换Greasemonkey中的子弹角色。我想正则表达式可以做到这一点,但我对它的精通程度不如你们中的许多人 例如,“SampleSite.com•页面标题”变为“SampleSite.com页面标题”。问题是在Greasemonkey到达角色时,角色已经被解析,我不知道如何让它识别符号 到目前为止,我已经尝试过这些,但都不起作用: newTitle = document.title.replace(/•/g, ""); newTitle = document.titl

全部。我正在寻找一种方法来替换Greasemonkey中的子弹角色。我想正则表达式可以做到这一点,但我对它的精通程度不如你们中的许多人

例如,“SampleSite.com•页面标题”变为“SampleSite.com页面标题”。问题是在Greasemonkey到达角色时,角色已经被解析,我不知道如何让它识别符号

到目前为止,我已经尝试过这些,但都不起作用:

newTitle = document.title.replace(/•/g, "");
newTitle = document.title.replace("•", ""); //just for grins, but didn't work anyway

对我有用。

如果Malvolio的解决方案不起作用,你可以这样做

newTitle = document.title.replace(/\&bull\;/g, '');
newTitle = newTitle.replace(/([^a-zA-Z0-9-_\s\/\\\(\)\'\"\&\+\.]+)/g, '');

&
之间的代码定义的HTML实体更换
·
&;米德多(可能在您的情况下)基于页面编码。在使用正则表达式替换之前,最好先对html进行编码。

如果找不到符号,可能该符号实际上是在标题中编码的?这接近于我需要的,但它没有考虑带句点或撇号的页面标题,所以我对其进行了一些修改。谢谢你的原始正则表达式!newTitle=document.title.replace(/([^a-zA-Z0-9-\s\/\()\.]+)/g');
newTitle = document.title.replace(/\&bull\;/g, '');
newTitle = newTitle.replace(/([^a-zA-Z0-9-_\s\/\\\(\)\'\"\&\+\.]+)/g, '');