I am kinda new to Regex and has been trying to build a code to remove duplicates.
The result should look like this 'abcd1"
My code is follow:
import re
text = 'aaaaabbbcccddd111'
while re.search(r'([a-z])(.*)\1', text):
text = re.sub(r'([a-z])(.*)\1', r'\1\2', text)
print(text)
However, it will not remove the "1", only the a-z characters.
What should I include to make this work?
Thanks!
re.sub(r'(.)\1*', r'\1', text)([a-z0-9])\1+and replace withr'\1'regex101.com/r/sYO49h/1