I have a string called "strtosearch2" like this:
[02112017 072755 332][1][ERROR]> ----Message : IDC_NO_MEDIA
[02112017 072755 332][1][INFO]> ----
[02112017 104502 724][1][ERROR]> ----Message : DEV_NOT_READY
[02112017 104502 724][1][INFO]> ----
[02112017 104503 331][1][ERROR]> ----Message : DEV_NOT_READY
[02112017 104503 331][1][INFO]> ----
I want to extract the dates which are having the lines "ERROR" only. I wrote my regex as follows:
down2Date= re.findall(r'\[(.*?)\s\d{6}\s\d{3}\]\[\d\]\[ERROR\]',strtosearch2,re.DOTALL)
output as follows:
02112017
02112017 072755 332][1][INFO]> ----
[02112017
02112017 104502 724][1][INFO]> ----
[02112017
My target output:
02112017
02112017
02112017
How can I fix this ?. Thank you
re.DOTALL.re.findall(r'(?m)^\[(\d+).*ERROR', strtosearch2)would work too.. if not, try to add relevant sample when asking :)