I have a log file in while I want to search for a pattern involving multiple lines using regular expression. From what I know, I am able to read and match only one line at once. How do I load a whole file in memory and do pattern matching?
I have a log file in which I am looking for assert message like this:
*** ASSERT: 0xb83c6056
*** type of assert: <xyz>
*** file: .
*** firmware revision: <xyz>
*** firmware build timestamp: <xyz>
*** seconds since 1970: <xyz>
*** at address: <xyz>
*** fault address: xyz>
*** Error sub-type: <xyz>
I am using the following regular expression.
re.compile(r'(\*){3}(\s){1}(ASSERT: )(.+)(\n){2}(\t)(\*){3}(\s){1}(type of assert: )(.+)(\n){2}(\t)(\*){3}(\s){1}(file: )(.+)(\n){2}(\t)(\*){3}(\s){1}(firmware revision: )(.+)(\n){2}(\t)(\*){3}(\s){1}(firmware build timestamp: )(.+)(\n){2}(\t)(\*){3}(\s){1}(seconds since 1970: )(.+)(\n){2}(\t)(\*){3}(\s){1}(at address: )(.+)(\n){2}(\t)(\*){3}(\s){1}(fault address: )(.+)(\n){2}(\t)(\*){3}(\s){1}(Error sub-type: )(.+)')
Please tell me how can I improve my regular expression in order to load the whole file at once and do the regex matching. Right now with my knowledge I am able to read line by line only.