Regex remove duplicate characters from a string by javascript
11:27 10 Oct 2013

I have found a way to remove repeated characters from a string using regular expressions.

function RemoveDuplicates() {
    var str = "aaabbbccc";
    var filtered = str.replace(/[^\w\s]|(.)\1/gi, "");  
    alert(filtered);
}

Output: abc this is working fine.

But if str = "aaabbbccccabbbbcccccc" then output is abcabc. Is there any way to get only unique characters or remove all duplicates one? Please let me know if there is any way.

javascript regex