SocialMediaFoci / debug_regex.py
Bismark
Update Space
5ab54b7
raw
history blame contribute delete
633 Bytes
import pandas as pd
import re
pattern = r"^(?P<Date>\d{1,2}/\d{1,2}/\d{2,4}),\s+(?P<Time>[\d:]+(?:\S*\s?[AP]M)?)\s+-\s+(?:(?P<Sender>.*?):\s+)?(?P<Message>.*)$"
lines = [
"12/12/23, 10:00 - User1: Hello",
"1/1/23, 1:00 - User2: Hi",
"10/10/2023, 10:00 PM - User3: Test",
"12/12/23, 10:00 - System Message"
]
df = pd.DataFrame({'line': lines})
extracted = df['line'].str.extract(pattern)
print("Extracted DataFrame:")
print(extracted)
print("\nRegex Match Check:")
for line in lines:
match = re.match(pattern, line)
print(f"'{line}' -> Match: {bool(match)}")
if match:
print(match.groupdict())