[英]Can't replace UTF-8 character with RegExp
I have a string with the UTF-8 character ↵
. 我有一个UTF-8字符的字符串↵
。 To my understanding, if you want to replace a UTF-8 character in a string, you specify the character with its hexadecimal representation, like so: 根据我的理解,如果要替换字符串中的UTF-8字符,请指定具有十六进制表示的字符,如下所示:
var string = "↵↵↵Middle↵↵↵";
console.log("Match? " + /\u21b5/.test("↵"));
console.log(string);
string = string.replace("/\u21b5/g", "");
console.log(string);
It is a match, but the replace is not working. 这是匹配,但替换不起作用。 What am I missing? 我错过了什么?
您正在使用字符串而不是正则表达式
string = string.replace(/\u21b5/g, "");
replace 更换
string = string.replace("/\u21b5/", "");
with 同
string = string.replace(/\u21b5/g, "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.