有没有办法列出字符串的重复字母?我想在我的函数中使用正则表达式,但现在它只告诉我是否有重复。我能以某种方式将它们推入阵列吗?
function repeating(str) {
//this part returns true/false
var hasDuplicates = (/([a-zA-Z]).*?\1/).test(str);
return hasDuplicates;
//I tried with something like this but it returns whole word, not letters
var duplicates = str.match(/(.).*\1/gi);
return duplicates;
}