Use JavaScript regex to replace numerical HTML entities with their actual characters
问题 I'm trying to use JavaScript & regex to replace numerical HTML entities with their actual Unicode characters, e.g. foo's bar → foo's bar This is what I got so far: "foo's bar".replace(/&#([^\s]*);/g, "$1"); // "foo39s bar" All that's left to do is to replace the number with String.fromCharCode($1) , but I can't seem to get it to work. How can I do this? 回答1: "foo's bar".replace(/&#(\d+);/g, function(match, match2) {return String.fromCharCode(+match2);}) 回答2: "foo's bar".replace(/&#([^\s]*);/g