title: Use JavaScript regex to replace numerical HTML entities with their actual characters
body: <p>I'm trying to use JavaScript &amp; regex to replace numerical HTML entities with their actual Unicode characters, e.g.</p>
  
  <pre><code>foo&amp;#39;s bar
  →
  foo's bar
  </code></pre>
  
  <p>This is what I got so far:</p>
  
  <pre><code>"foo&amp;#39;s bar".replace(/&amp;#([^\s]*);/g, "$1"); // "foo39s bar"
  </code></pre>
  
  <p>All that's left to do is to replace the number with <code>String.fromCharCode($1)</code>, but I can't seem to get it to work. How can I do this?</p>