I'm trying to parse some conversations from an app in a .txt file with Python's re module, but despite working on regex101 when used on a sample of the file, it doesn't work properly when I open the file and actually try to parse it.
The structure of the txt file is dd/mm/yyyy hh:mm - Message Author: message text\n, and I'm trying to get only the Name: message \n parts. I'm using the following pattern (?<=\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}\s\-\s)(.*:.*$). My code is looking more or less like the following:
buffer = open(file, 'r', encoding = 'UTF-8').read()
pattern = re.compile(r'(?<=\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}\s\-\s)(.*:\s)(.*$)')
matches = re.findall(pattern, buffer)
As the title says, though, findall returns and empty list, and I don't know why. The following sample works as expected on regex101:
20/04/2021 09:54 - Person 1: this is an example text. Will it match?
20/04/2021 09:54 - Person 2: I think it does.