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