I have a log file with a consistent date in my log file.
ex:
date1
date2
...
The date means the number of logs in my log file. I was wondering how can print the dates from the log file using Regular expressions
what I have tried:
import re
dateRegex = re.compile('^\w{3}\s\d\d:\d\d:\d\d')
f = open("logfile.log","r")
for line in f.readlines():
matches = re.findall(dateRegex,line)
print matches
The output I am getting is (many []):
[]
[]
[]
...
...
ifsomewhere to avoid printing when you have no matches. You might also want to print the element of the result list, as opposed to the list itself.Apr 20 07:04:53r'^\w{3}\s\d\d\s\d\d:\d\d:\d\d'rfor another case and it worked without it