multiline regular expression (replace)

half.italian at gmail.com half.italian at gmail.com
Tue May 29 05:46:41 EDT 2007


On May 29, 2:03 am, Zdenek Maxa <zdenekm... at yahoo.co.uk> wrote:
> Hi all,
>
> I would like to perform regular expression replace (e.g. removing
> everything from within tags in a XML file) with multiple-line pattern.
> How can I do this?
>
> where = open("filename").read()
> multilinePattern = "^<tag> .... <\/tag>$"
> re.search(multilinePattern, where, re.MULTILINE)
>
> Thanks greatly,
> Zdenek

Why not use an xml package for working with xml files?  I'm sure
they'll handle your multiline tags.

http://effbot.org/zone/element-index.htm
http://codespeak.net/lxml/

~Sean




More information about the Python-list mailing list