I found a code snippet to remove duplicated consecutive characters and reserve the first character in Python using regular expressions from a website, for example:
import re
re.sub(r'(?s)(.)(?=.*\1)','','aabbcc')
But there is a defect that if the line is "aabbccaabb", it ignores the first "aa", "bb" and produces "cab".
re.sub(r'(?s)(.)(?=.*\1)','','aabbccaabb')
Is there a way to solve it with regex?
source
share