Skip to content

Instantly share code, notes, and snippets.

@zhgqthomas
Created December 8, 2017 07:35
Show Gist options
  • Save zhgqthomas/c9801b9294daae54592679918a27d29b to your computer and use it in GitHub Desktop.
Save zhgqthomas/c9801b9294daae54592679918a27d29b to your computer and use it in GitHub Desktop.
decode HTML Entity
function htmlDecode(str) {
// 有 x 则表示是16进制,$1 就是匹配是否有 x,$2 就是匹配出的第二个括号捕获到的内容,将 $2 以对应进制表示转换
str = str.replace(/&#(x)?(\w+);/g, function($, $1, $2) {
return String.fromCharCode(parseInt($2, $1? 16: 10));
});
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment