Regular Expression question

stevebread at yahoo.com stevebread at yahoo.com
Mon Aug 21 05:51:56 EDT 2006


Hi, I am having some difficulty trying to create a regular expression.

Consider:

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

Whenever a tag1 is followed by a tag 2, I want to retrieve the values
of the tag1:name and tag2:value attributes. So my end result here
should be
john, tall
jack, short

My low quality regexp
re.compile('tag1.+?name="(.+?)".*?(?!tag1).*?="adj__(.*?)__',
re.DOTALL)

cannot handle the case where there is a tag1 that is not followed by a
tag2. findall returns
john, tall
joe, short

Ideas?

Thanks.




More information about the Python-list mailing list