Tholle Tholle - 1 year ago 157
Javascript Question

Can't replace UTF-8 character with RegExp

I have a string with the UTF-8 character

. 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:

var string = "↵↵↵Middle↵↵↵";
console.log("Match? " + /\u21b5/.test("↵"));
string = string.replace("/\u21b5/g", "");

It is a match, but the replace is not working. What am I missing?


Answer Source

You are using a string not a regex

string = string.replace(/\u21b5/g, "");