txt = '0 Marriage of MARY ROCHE
1 in 1880
2 Group Registration ID\tN/R
3 SR District/Reg Area\tCork
4 Returns Year\t1880
5 Returns Quarter\t4
6 Returns Volume No\t5
7 Returns Page No\t0110
8 Marriage of MARY ROCHE
9 in 1880
10 Group Registration ID\tN/R
11 SR District/Reg Area\tEnniscorthy
12 Returns Year\t1880
13 Returns Quarter\t3
14 Returns Volume No\t4
15 Returns Page No\t276"
The above is a snippet of a Marriage Records Dataset. Each 8 lines correspond to a new woman's record. I'm attempting to extract the key details (year, area, quarter, volume, page no) through regex expressions.
year = re.compile(r'in\s\d{4}')
area = re.compile(r'Area\t[A-Za-z]+(?:\s[A-Za-z]+)*$')
fdata = []
file = open('C:\\Downloads\\mary_roche.txt', 'r')
for line in file:
year_matches = year.finditer(line)
area_matches = area.finditer(line)
for a in area_matches:
for y in year_matches:
fdata.append([y.group(),a.group()])
print(len(fdata))
print(fdata)
When I use these expressions individually, they work, but when I try to add the two to a list of lists, I get nothing. My end goal is to create expressions for all five key details and store them in an orderly fashion, i.e [[woman1], [woman2], [woman3]...etc]
Any help here is greatly appreciated. Cheers!