Skip to content

Instantly share code, notes, and snippets.

@cuixiping
Created April 29, 2013 03:58
Show Gist options
  • Save cuixiping/5479633 to your computer and use it in GitHub Desktop.
Save cuixiping/5479633 to your computer and use it in GitHub Desktop.
1 行正则去除重复字符或者重复单词
//去除重复字符
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