<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3603" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2>Hi,</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>I am using a python
parser for parsing the incoming message from syslog-ng. In my log messages
some fields are optional and some are not.I want to know how to handle these
optional parameters in the python regual expression.</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>for
example:</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>sample log
:-></FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2> </FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>
log='Sep 15 22:23:37 ecis007 <STRONG>codeSystemName=5</STRONG>
UserID="Admin"'</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>regular expression
:-></FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>
aregex=re.compile(r"(?P<destmonth>\S+) (?P<devicedate>\S+)
(?P<devtime>\S+) (?P<devicename>\S+)
codeSystemName=(?P<EventIDcodeSystemName>.*)")<BR></FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>if I run the
following python command then i can get all the
parameters</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2>r=aregex.match(log2)</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2>but</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>if
"codeSystemName=5" is a optional parameters and it is not in some messages then
my parser is not able to parse the message.</DIV></FONT></SPAN>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2> log='Sep 15 22:23:37 ecis007
UserID="Admin'</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial size=2>let me know how to
write the regex for optional parameters ?</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009></SPAN> </DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2>Regards,</FONT></SPAN></DIV>
<DIV><SPAN class=216102205-16092009><FONT face=Arial
size=2>Vaibhav</FONT></SPAN></DIV></BODY></HTML>