kent37 at tds.net
Tue Dec 27 13:28:10 CET 2005
Danny Yoo wrote:
>>Dec 18 10:04:45 dragon logger: TCPWRAP: SERVICE=sshd@::ffff:192.168.0.1
> Hi Will,
> Observation: the output above looks comma delimited, at least the stuff
> after the 'TCPWRAP:' part.
> The line given as example doesn't appear to have whitespace in the places
> that the regular expression expects. It does contain commas as delimiters
> between the key/value pairs encoded in the line.
Expanding on Danny's comment...
\S*\s matches any amount of non-whitespace followed by one whitespace.
This doesn't match your sample. It looks like you want to match
non-comma followed by comma. For example this will match the first field:
Presumably you will want to pull out the value of the field so enclose
it in parenthesis to make a group:
Another thing I notice about your regex is it doesn't include all the
fields in the sample, for example TYPE. If the fields are always the
same you can just include them in your regex. If they vary you can try
to make the regex skip them, use a different regex for each field, or
try Danny's approach of using str.split() to break apart the data.
The Regex Demo program that comes with Python is handy for creating and
testing regexes. Look in C:\Python24\Tools\Scripts\redemo.py or the
More information about the Tutor