Regex question repeated chars

How do I make it so it matches all 6 i’s?

Code so far:

function duplicateCount(text){
  return text.match(/(.+)(?=.*?\1)/gi)

// -> [ 'I', 'i', 'i', 'i', 'i' ]

your regex matches only if after the captured group it there is something else equal, so the last one is never matched - I don’t know what you could do using this approach to match also the last one

Thanks, I’ll experiment with another approach.