File size: 994 Bytes
026cb4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import re

def extract_multi_records(text):
    lines = text.split("\n")
    data = []

    for line in lines:
        line = line.strip()

        # Skip empty lines
        if not line:
            continue

        words = line.split()

        # Skip header row
        if any(word.lower() in ["name", "date", "amount"] for word in words):
            continue

        # Find date
        date = re.findall(r'\d{2}[-/]\d{2}[-/]\d{4}', line)

        # Find amount (last number in line)
        amount = re.findall(r'\d+', line)

        # Extract name (first word only if valid)
        name = words[0] if words else "Unknown"

        # Validate name (should not be numeric or date)
        if name.isdigit():
            continue

        # Save record if valid
        if date and amount:
            data.append({
                "Name": name,
                "Date": date[0],
                "Amount": amount[-1]
            })

    return data