I have a logfile having contains as below
log=
Using data from (yyyy/mm/dd): 2011/8/3
0 files queued for scanning.
Warning: E:\test\Händler.pdf File not Found.
Loading com, please wait.
1520 file scanned.
I want to write a regex to detect the Warning message because this is optional warning comming sometimes I wrote the basic regext to the data which will coming compulsory.
logd = re.compile("Using\sdata\sfrom\s\(yyyy/mm/dd\):\s(? P<Defs_Date>\d{4}/\d+/\d+)[^\w\d] ")
data = Re.search(logd, log).groupdict()
Output will be :
{'Defs_Date': '2011/8/3'}
Since the warning is optional so how I should handle it. I am not good in writting in regex. And please suggest me any good examples or links to get master in regex.
One way to handle optional parts is to use
regex text (optional part|). The part inside parenthesis will match either “optional part” (which can be a regex on its own) or nothing.