import string text = "a" + text + "a" x = 0 while x <= len(text) - 9: text1 = text[x:x+9] if text1[0] not in string.uppercase: for y in range(1, 4): if text1[y] not in string.uppercase: x = x+y break else: if text1[4] in string.lowercase: for z in range(5,8): if text1[z] not in string.uppercase: x = x+4 break else: if text1[8] not in string.uppercase: print text1[4], x = x+8 else: x = x+4 else: x = x+1