How to use re to find consecutive, repeated chars

后端 未结 3 527
醉梦人生
醉梦人生 2020-12-01 11:05

I want to find all consecutive, repeated character blocks in a string. For example, consider the following:

s = r\'http://www.google.com/search=ooo-jjj\'
         


        
3条回答
  •  庸人自扰
    2020-12-01 11:38

    The following code should solve your problem:

    s="abc def aaa bbb ccc def hhh"
    
    for match in re.finditer(r"(\w)\1\1", s):
        print s[match.start():match.end()]
    

提交回复
热议问题