Use JavaScript regex to replace numerical HTML entities with their actual characters

后端 未结 4 778
南旧
南旧 2020-12-29 16:22

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
         


        
4条回答
  •  余生分开走
    2020-12-29 16:55

    "foo's bar".replace(/&#(\d+);/g, function(match, match2) {return String.fromCharCode(+match2);})
    

提交回复
热议问题