var str = 'aabbbbbaccchh';var reg = /(.)\1*/g; var arr = str.match(reg); // ["aa", "bbbbb", "a", "ccc", "hh"] arr.sort((a,b)=>{return b.length-a.length})[0] "bbbbb"