简体   繁体   English

Javascript正则表达式无法替换某些特殊字符

[英]Javascript regex unable to replace certain special characters

I have this Javascript regex: 我有这个Javascript正则表达式:

 body = body.replace(/[\x80-\xFF]/g,"#");

which I am hoping to use to replace characters in the table here . 我希望用它替换这里表中的字符。 However I am unable to replace the characters highlighted in red on the table in that page. 但是,我无法替换该页面上表格中以红色突出显示的字符。 I couldn't comprehend why. 我不明白为什么。 Can someone enlighten me on why it is happening like that and what the workaround? 有人可以启发我为什么会发生这种情况以及解决方法吗? Thank you. 谢谢。

一种解决方法是改用Unicode范围,当我在控制台的示例页面上尝试此方法时(我认为您要这样做):

document.body.innerHTML = document.body.innerHTML.replace(/[\u0152-\u2122]/g,"#");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM