re module non-greedy matches broken

lothar lothar at ultimathule.nul
Tue Apr 5 12:11:05 EDT 2005


give an re to find every innermost "table" element:

innertabdoc = """
<table border="0" cellspacing="0" cellpadding="0">
  <tr><td>
<table border="0" cellspacing="0" cellpadding="0">
  <tr><td> <a>n</a>
  </td></tr>
</table>
  </td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
  <tr><td>
<table border="0" cellspacing="0" cellpadding="0">
  <tr><td> </td> <td>
<table border="0" cellspacing="0" cellpadding="0">
  <tr><td> <p>y</p> <td> z</td>
  </td></tr>
</table>
  </td></tr>
</table>
  </td></tr>
  <tr><td>
<table border="0" cellspacing="0" cellpadding="0">
  <tr><td>
  </td></tr>
</table>
  </td></tr>
</table>
"""

give an re to find every "pre" element directly followed by an "a" element:

preadoc = """
<pre>
a <i>r</i> n
</pre>
<pre>
<b>l</b> y
</pre><a href="#n1"></a>
<pre>
r
</pre>
<pre>
f <font>g</font> z
</pre>
<pre>
m <i>b</i> u <i>c</i> v
</pre><a href="#n2"></a>
<pre>
u
</pre>
"""

"John Ridley" <ojokimu at yahoo.co.uk> wrote in message
news:mailman.1325.1112651826.1799.python-list at python.org...
>

> Could you post some real-world examples of the problems you are trying
> to deal with, please? Trying to come up with general solutions for
> arbitrarily complex patterns is a bit to hard for me :)







More information about the Python-list mailing list