title: PHP regular expression for multiple tables
body: <p>I need  help with building regular expression for text separating.
  Now I have some text like </p>
  
  <pre><code>text text text
  text text text
  &lt;div&gt; text text text &lt;/div&gt;
  &lt;table class="table1"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  text text text
  text text text
  text text text
  &lt;table class="table2"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  text text text
  text text text
  text text text
  </code></pre>
  
  <p>I need to create a regular expression that would separate the text and tables.
  Now I have regular expression</p>
  
  <pre><code>preg_match_all( "/(.*)(&lt;table(?s).*?\/table&gt;)(.*)/si", $value[ 'TEXT' ], $matches );
  </code></pre>
  
  <p>And this expression works fine for the text like </p>
  
  <pre><code>text text text
  text text text
  &lt;div&gt; text text text &lt;/div&gt;
  &lt;table class="table1"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>It separate to the</p>
  
  <pre><code>text text text
  text text text
  &lt;div&gt; text text text &lt;/div&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    &lt;table class="table1"&gt;
      &lt;tr&gt;
      &lt;td&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>But for the text </p>
  
  <pre><code>text text text
  text text text
  &lt;div&gt; text text text &lt;/div&gt;
  &lt;table class="table1"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  text text text
  text text text
  text text text
  &lt;table class="table2"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  text text text
  text text text
  text text text
  </code></pre>
  
  <p>my regular expression doesnot work. It's return array with</p>
  
  <pre><code>[0] =&gt;"text text text
      text text text
      &lt;div&gt; text text text &lt;/div&gt;
      &lt;table class="table1"&gt;
      &lt;tr&gt;
      &lt;td&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      text text text
      text text text
      text text text",
  [1]=&gt;"&lt;table class="table2"&gt;
      &lt;tr&gt;
      &lt;td&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;",
  [2]=&gt;"text text text
      text text text
      text text text"
  </code></pre>
  
  <p>How to build right regular expression?</p>