Spaces:
Sleeping
Sleeping
| 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 |