RegExp match repeated characters

前端 未结 6 1856
陌清茗
陌清茗 2020-11-30 03:47

For example I have string:

 aacbbbqq

As the result I want to have following matches:

 (aa, c, bbb, qq)  
6条回答
  •  日久生厌
    2020-11-30 04:27

    The findall method will work if you capture the back-reference like so:

    result = [match[1] + match[0] for match in re.findall(r"(.)(\1*)", string)]
    

提交回复
热议问题