Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing more than two consecutive chars

Tags:

python

I want to remove any char which repeats more than two times consecutive.

import re
re.sub(r'([a-z])\1+', r'\1', 'ffffffbbbbbbbqqq')

it's returning me fbq, while I need ffbbqq. The goal is pre-process the string before doing a spell checking. What am I doing wrong?

like image 314
cybertextron Avatar asked May 29 '26 09:05

cybertextron


1 Answers

In [204]: import re

In [205]: re.sub(r'([a-z])\1+', r'\1\1', 'ffffffbbbbbbbqqq')
Out[205]: 'ffbbqq'
like image 199
unutbu Avatar answered Jun 01 '26 00:06

unutbu