Skip to content

Instantly share code, notes, and snippets.

@dailc
Created September 5, 2017 08:32
Show Gist options
  • Save dailc/cf7ef4aecc2f62f9b37db3db1f31904e to your computer and use it in GitHub Desktop.
Save dailc/cf7ef4aecc2f62f9b37db3db1f31904e to your computer and use it in GitHub Desktop.
[正则表达式小技巧] 正则表达式的一些小技巧 #tags: 正则表达式, regex
## 转义uri
function uncodeHTML(str) {
return str.replace(/(<)|(&npsp;)|(>)|(&)|(")|(')/g,
function($0, $1, $2, $3, $4, $5, $6) {
return ($1 && '<') || ($2 && ' ') || ($3 && '>') || ($4 && '&amp;') || ($5 && '"') || ($6 && '\'');
});
}
console.log(uncodeHTML('测试&lt;测试2&npsp;测试3&gt;测试4&amp;测试5&quot;测试6&apos;测试7&lt;'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment