Le 21/04/05 16:19, « rbt » <[EMAIL PROTECTED]> a écrit : > Peter Hansen wrote: >> rbt wrote: >> >>> Output from 'netstat -b' on a win2003 server will show what binary is >>> responsible for the connection. For example, it may list something >>> like this along with other connection specific data: >>> >>> [lsass.exe] >>> [System] >>> [firefox.exe] >>> [iexplorer.exe] >>> >>> How might I process the output so that anything within brackets is >>> recorded to a log file of my own making? I know how to parse and >>> record things to a file, I don't know how to look make '[' and ']' >>> appear as special characters so that I can record what's between them. >> >> >> Does this help? >> >>>>> import re >>>>> >>>>> s = '''stuff [lsass.exe] >> ... [System] more stuff >> ... xxxxx [firefox.exe] ...... >> ... ''' >>>>> >>>>> re.findall(r'\[([^]]*)\]', s) >> ['lsass.exe', 'System', 'firefox.exe'] > > Yes, it does... may take me a few minutes to get my head around it > though. Why do re's have to be so arcane and complicated... especially > in Python?
Items = s.split('[') For item in items: end = item.find(']') label = item[:end] Not tested, ugly and slow, but may be more understandable -- Convert from markup to markup: http://fgranger.net1.nerim.net/mtom/ -- http://mail.python.org/mailman/listinfo/python-list