# Search for lines that start with From and a character # followed by a two digit number between 00 and 99 followed by ':' # Then print the number if one is found import re hand = open('mbox-short.txt') for line in hand: line = line.rstrip() x = re.findall('^From .* ([0-9][0-9]):', line) if len(x) > 0: print(x)