Get duplicate characters in string

后端 未结 3 1242
一向
一向 2020-12-22 06:36

I try to match/get all repetitions in a string. This is what I\'ve done so far:

var str = \'abcabc123123\';
var REPEATED_CHARS_REGEX = /(.).*\\1/gi;

console         


        
3条回答
  •  攒了一身酷
    2020-12-22 06:52

    The answer above returns more duplicates than there actually are. The second for loop causes the problem and is unnecessary. Try this:

    function stringParse(string){
      var arr = string.split("");
      for(var i = 0; i

提交回复
热议问题