John Machin <[EMAIL PROTECTED]> writes: > Uh-oh. > > Try this: > >>>> pat = re.compile('(?<=abc\n).*?(?=xyz\n)', re.DOTALL) >>>> re.sub(pat, '', linestr) > 'blahfubarabc\nxyz\nxyzzy'
This regexp still has a problem. It may remove the lines between two lines like 'aaabc' and 'xxxyz' (and also removes the first two 'x's in 'xxxyz'). The following regexp works better: pattern = re.compile('(?<=^abc\n).*?(?=^xyz\n)', re.DOTALL | re.MULTILINE) >>> lines = '''line1 ... abc ... line2 ... xyz ... line3 ... aaabc ... line4 ... xxxyz ... line5''' >>> pattern = re.compile('(?<=^abc\n).*?(?=^xyz\n)', re.DOTALL | re.MULTILINE) >>> print pattern.sub('', lines) line1 abc xyz line3 aaabc line4 xxxyz line5 >>> - Baoqiu -- Baoqiu Cui <cbaoqiu at yahoo.com> -- http://mail.python.org/mailman/listinfo/python-list