I\'m trying to find characters that are repeated 3 times or more, for example I want to take the following strings:
(\'aaa\'
, \'buuuuut\'
,
>>> s = 'abbcccffffdd'
>>> s = re.sub(r'(\w)\1(\1+)',r'\1',s)
>>> s
'abbcd'
Look at this:
>>> mystr = 'buuuuuttttt'
>>> re.sub(r'(.)\1{2,}', r'\1', mystr)
'but'
>>> mystr = 'buttt'
>>> re.sub(r'(.)\1{2,}', r'\1', mystr)
'but'
>>>
Maybe try something like this:
s = re.sub(r'(\w)\1\1+', r'\1', s)