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

后端 未结 4 764
南旧
南旧 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 17:14

    "foo's bar".replace(/&#([^\s]*);/g, function(x, y) { return String.fromCharCode(y) })
    

    First argument (x) is a "'" in current example. y is 39.

提交回复
热议问题