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