fork download
  1. import re
  2.  
  3. pattern = r"(\d)\1{2,}|(\d)\2"
  4. strings = ["123456678", "12334566", "12345654554888", "1221", "66", "122", "221", "1234566678", "1222", "2221", "111"]
  5.  
  6. for s in strings:
  7. match = re.search(pattern, s)
  8. if match and match.group(2):
  9. print ("Match: " + match.string)
  10. else:
  11. print ("No match: " + s)
Success #stdin #stdout 0.02s 9600KB
stdin
Standard input is empty
stdout
Match: 123456678
Match: 12334566
Match: 12345654554888
Match: 1221
Match: 66
Match: 122
Match: 221
No match: 1234566678
No match: 1222
No match: 2221
No match: 111