(Dec-12-2022, 05:59 PM)Gribouillis Wrote: Try with the re.DOTALL flag
footer_pattern = re.search("(?s)^JOHN.*Confidential$", text)
Just added the (?s) and re.DOTALL and got the same result. Footer is still in the text file. Does this look correct for that flag?
with pdfplumber.open(pdfFilePath) as pdf: k = len(pdf.pages) for i in range(1, k): page = pdf.pages[i] text = (page.extract_text()) footer_pattern = re.search("(?s)^JOHN.*Confidential$", text, re.DOTALL) if footer_pattern: text = text.replace(footer_pattern, '') with open(txtFilePath, 'a') as txtFile: txtFile.write(text)