In my python code I receive a log file which I want to store so that the user can read it. The log file contains special characters like: ^[[m^[(B which I want to remove.
Example line from the log file: <13>Jan 11 13:14:39 [2023-01-11, 13:14:39.700] fio_start.info:^[[m^[(B: Cleanup started
According to the answer given in this thread How can I remove the ANSI escape sequences from a string in python
I have used re.compile with different regular expressions e.g. like this:
ansi_escape = re.compile(r'(?:\x1B[@-Z\-_]|[\x80-\x9A\x9C-\x9F]|(?:\x1B[|\x9B)[0-?][ -/][@-~])') new_fileContents = ansi_escape.sub('', str(fileContents))
which removes the '^[[m' but not the '^[(B':
<13>Jan 11 13:14:39 [2023-01-11, 13:14:39.700] fio_start.info:^[(B: Cleanup started
Can someone please help me to find the correct regex to remove also the ^[(B?