Get duplicate characters in string

后端 未结 3 1243
一向
一向 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:53

    This solution may be used if you don't want to use regex:

    function test() {
        var stringToTest = 'find the first duplicate character in the string';
        var a = stringToTest.split('');
        for (var i=0; i

提交回复
热议问题