Created
December 8, 2017 07:35
-
-
Save zhgqthomas/c9801b9294daae54592679918a27d29b to your computer and use it in GitHub Desktop.
decode HTML Entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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