Jay -

Thanks for the pyparsing plug.

Here is how the OP's program would look using pyparsing:


import pyparsing

fp = file('filename')
data = fp.read()
fp.close()

foo = '''stuff   [lsass.exe]
[System]  more stuff
xxxxx [firefox.exe] ......
'''

LBRACK = pyparsing.Literal("[").suppress()
RBRACK = pyparsing.Literal("]").suppress()
brackettedStuff = LBRACK + pyparsing.SkipTo( RBRACK ) + RBRACK

for tokens,start,end in brackettedStuff.scanString( foo ):
    print tokens[0]

--- fin ---
Now this is not nearly as terse as the regexp version, nor will it run
as fast.  But I think I'd rather come back to this version 6 months
from now and try to figure "what was this program doing again?".

-- Paul

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to