问题描述:

I have str like "Buy new XXX sex bla-bla-bla" and I need to find if str have XXX or ZZZ, or any 3 or more repeated characters. Of course I can do some array and go down the wrong way, but maybe is here some trick? Thank you.

PS. Google doesn't help.

网友答案:
import re

if re.search(r'(.)\1\1', mystr):
   print "Has triple letters"
网友答案:

something like this:

In [14]: for x,y,z in zip(strs,strs[1:],strs[2:]):
   ....:     if x==y==z and x:
   ....:         print x+y+z
   ....:         
XXX
相关阅读:
Top