import re with open('polish_wiki_excerpt.in', encoding='utf8') as file: lines = file.readlines() pattern = r'19\d\d r\.' for line in lines: line = line.strip() x = re.search(pattern, line) if x: print(line)