import re import csv with open("bigHtmlFile.html", "r") as infile: html_dump = infile.read() # Define the regular expressions with negative lookbehind regex_title = r"(?= 0 else 0 debit = -fraction if fraction < 0 else 0 # Format the date formatted_date = date[:10].replace('-', '/') # Write the row to the CSV file writer.writerow([title + ' ' + counterpart, counterpart, credit, debit, formatted_date])