Regular Expressions
Isaac To
iketo2 at netscape.net
Sat Aug 14 12:13:37 EDT 2004
>>>>> "Jens" == Jens Thiede <jens.news at webgear.co.za> writes:
Jens> What is the easiest way to generate a list that contains all
Jens> the remnants of re.findall (the inverse of the following).
You mean, complement?
Jens> re.split doesn't seem to work quite well
Why?
>>> obj=re.compile(r'<t>.*?</t>', re.S|re.I)
>>> obj.split('def<T>abc\n def</T>ghi jkl\nmno\n<t>abc</t>haha')
['def', 'ghi jkl\nmno\n', 'haha']
>>> obj.findall('def<T>abc\n def</T>ghi jkl\nmno\n<t>abc</t>haha')
['<T>abc\n def</T>', '<t>abc</t>']
>>> obj=re.compile(r'<t>.*</t>', re.S|re.I)
>>> obj.split('def<T>abc\n def</T>ghi jkl\nmno\n<t>abc</t>haha')
['def', 'haha']
>>> obj.findall('def<T>abc\n def</T>ghi jkl\nmno\n<t>abc</t>haha')
['<T>abc\n def</T>ghi jkl\nmno\n<t>abc</t>']
Looks like it is doing the job, right?
Regards,
Isaac.
More information about the Python-list
mailing list