jfz-2023-s464983/TaskD03/run.py

18 lines
526 B
Python

import re
#Write a program to find lines containing date from 1900 to 1999 in format '19XX r.' no matter what on the left or right of the expression.
#Note that part ' r.' is obligatory.
#Do use regular expressions.
def data_reg(file_path):
licznik = 0
with open(file_path, 'r', encoding='utf-8') as file:
for line in file:
licznik += 1
if (re.search(".*19\d{2} r\..*", line)):
print(f"{licznik}: {line.strip()}")
file_path = 'TaskD03\simple.in'
data_reg(file_path)