[Tutor] regex

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Dec 27 10:45:19 CET 2005

> Dec 18 10:04:45 dragon logger: TCPWRAP: SERVICE=sshd@::ffff:

Hi Will,

Observation: the output above looks comma delimited, at least the stuff
after the 'TCPWRAP:' part.

> self.twist_fail_re =

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.

There's more information on regular expressions here:


that should help you get started.

As an aside: the structure of the log line above is simple enough that you
might not even need regexes --- regular string methods might just be
powerful enough.  For example, strings have a 'split()' method to break a
string into a list of substrings:

>>> 'hello,world,this,is,a,test'.split(",")
['hello', 'world', 'this', 'is', 'a', 'test']

If you have more questions, please feel free to ask.

More information about the Tutor mailing list