Самая длинная подстрока

function func(line) {
  let reg = /(\w)\1+/g;
  let longest = line.match(reg).sort((a, b) => {
    a.length - b.length
  }).pop();
  console.log(line + ' : ' + longest);
}

func('ddvvrwwwrggg');
func('sdsffffse');
func('abababaab');
func('aaabbcaaaa');
func('aaaasdfbbbbyyyweryyyuurweuuuuuu');
 Run code snippet
Troubled Tamarin