Regular Expression question

Rob Wolfe blue99 at interia.pl
Mon Aug 21 10:29:07 EDT 2006


stevebread at yahoo.com wrote:
> got zero results on this one :)

Really?

>>> s = '''<tag1 name="john"/>  <br/> <tag2 value="adj__tall__"/>
<tag1 name="joe"/>
<tag1 name="jack"/>
<tag2 value="adj__short__"/>'''

>>> pat = re.compile('tag1.+?name="(.+?)".*?(?:<)(?=tag2).*?="adj__(.*?)__', re.DOTALL)
>>> m = re.findall(pat, s)
>>> m
[('john', 'tall'), ('joe', 'short')]


Regards,
Rob




More information about the Python-list mailing list