0

I'm trying to create a regular expression in python that matches for the same character repeating itself at least twice. Check out the following examples:

'abbcdeee'  # ['bb', 'eee']
'abcde'  # []
'aaabbbbcc'  # ['aaa', 'bbbb', 'cc']

I have the following so far but it only returns the single item, not the entire repetitive string:

matches = re.findall(r'(.)\1{1,}', 'abbcdeee')
print(matches)  # ['b', 'e']
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146

1 Answers1

0

You could add another global group and take the first item in each tuple:

matches = re.findall(r'((.)\2+)', 'abbcdeee')
result = [item[0] for item in matches]
EmilioPeJu
  • 361
  • 1
  • 5