Created
April 29, 2013 03:58
-
-
Save cuixiping/5479633 to your computer and use it in GitHub Desktop.
1 行正则去除重复字符或者重复单词
This file contains hidden or 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
//去除重复字符 | |
var str='aabbaabbcddcabcadbcad'; | |
var str2=str.replace(/(.)(?=.*\1)/g,''); | |
document.writeln(str2); //bcad | |
//去除重复单词 | |
var str='one two two one two one 99 two 99'; | |
var str2=str.replace(/(\b\w+\b) (?=.*\1)/g,''); | |
document.writeln(str2); //one two 99 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment