title: Regex matching table rows in HTML
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3577641/best-methods-to-parse-html-with-php">Best methods to parse HTML with PHP</a>  </p>
  </blockquote>
  
  
  
  <p>I'm having a bit of trouble matching table rows with preg. Here is my expression:</p>
  
  <pre><code>&lt;TR[a-z\=\"a-z0-9 ]*&gt;([\{\}\(\)\^\=\$\&amp;\.\_\%\#\!\@\=\&lt;\&gt;\:\;\,\~\`\'\*\?\/\+\|\[\]\|\-a-zA-Z0-9À-ÿ\n\r ]*)&lt;\/TR&gt;
  </code></pre>
  
  <p>As you can see, it tries to mach everything in-between TR tags (including all symbols.) That part works great, however when dealing with multiple table rows, it often takes multiple table rows as ONE match, rather than a match for each table row:</p>
  
  <pre><code>&lt;TR&gt;
   &lt;TD&gt;test&lt;/TD&gt;
  &lt;/TR&gt;
  &lt;TR&gt;
   &lt;TD&gt;test2&lt;/TD&gt;
  &lt;/TR&gt;
  </code></pre>
  
  <p>yields:</p>
  
  <pre><code>Array
      (
          [0] =&gt; &lt;TD&gt;test&lt;/TD&gt;
                 &lt;TD&gt;test2&lt;/TD&gt;
      )
  </code></pre>
  
  <p>rather than what I want it to:</p>
  
  <pre><code>Array
      (
          [0] =&gt; &lt;TD&gt;test&lt;/TD&gt;
          [1] =&gt; &lt;TD&gt;test2&lt;/TD&gt;
      )
  </code></pre>
  
  <p>I realize that the reason for this is because it's match the symbols, and the search naturally takes the rest of the rows until it hits the last one.</p>
  
  <p>So basically, I'm wondering if someone can help me add to the expression so that it will exclude anything with "TR" in between the TR tags, as to prevent it from matching multiple rows.</p>