Regex to remove repeated character pattern in a string

前端 未结 4 1700
梦毁少年i
梦毁少年i 2020-12-14 22:30

I have a string that may have a repeated character pattern, e.g.

\'xyzzyxxyzzyxxyzzyx\'

I need to write a regex that would replace such str

4条回答
  •  情话喂你
    2020-12-14 23:18

    How (using re module) write function, that remove all duplications.

    import re
    def remove_duplications(string):
        return re.sub(r'(.+?)\1+', r'\1', string)
    

提交回复
热议问题