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 Answer