title: Improve a regex statement in order to be as efficient as it can be
body: <p>I have a PHP program that, at some point, needs to analyze a big amount of HTML+javascript text to parse info.
  All I want to parse needs to be in two parts.</p>
  
  <ol>
  <li>Seperate all "HTML goups" to parse</li>
  <li>Parse each HTML group to get the needed information.</li>
  </ol>
  
  <p>In the 1st parse it needs to find:</p>
  
  <pre><code>&lt;div id="myHome"
  </code></pre>
  
  <p>And start capturing after that tag. Then stop capturing before</p>
  
  <pre><code>&lt;span id="nReaders"
  </code></pre>
  
  <p>And capture the number that comes after this tag and stop.</p>
  
  <p>In the 2nd parse use the capture nº 1 (0 has the whole thing and 2 has the number) from the parse made before and then find
  .</p>
  
  <p>I already have code to do that and it works. Is there a way to improve this, make it easier for the machine to parse?</p>
  
  <pre><code>preg_match_all('%&lt;div id="myHome"[^&gt;]&gt;(.*?)&lt;span id="nReaders[^&gt;]&gt;([0-9]+)&lt;"%msi', $data, $results, PREG_SET_ORDER);
  foreach($results AS $result){
      preg_match_all('%&lt;div class="myplacement".*?[.]php[?]((?:next|before))=([0-9]+).*?&lt;tbody.*?&lt;td[^&gt;]&gt;.*?[0-9]+"%msi', $result[1], $mydata, PREG_SET_ORDER);
  //takes care of the data and finish the program
  </code></pre>
  
  <p>Note: I need this for a freeware program so it must be as general as possible and, if possible, not use php extensions</p>
  
  <p>ADD:
  I ommitted some parts here because I didn't expect for answers like those.
  There is also a need to parse text inside one of the  tags that is in the document. It may be the 6th 7th or 8th tag but I know it is after a certain tag. The parser I've checked (thx profitphp) does work to find the script tag. What now?
  There are more than 1 tag with the same class. I want them all. But I want only with also one of a list of classes.....
  Where can I find instructions and demos and limitations of DOM parsers (like the one in <a href="http://simplehtmldom.sourceforge.net/" rel="nofollow">http://simplehtmldom.sourceforge.net/</a>)? I need something that will work on, at least, a big amount of free servers.
  Another thing. How do I parse this part:
  "php?=([0-9]+)"
  with those HTML parsers?</p>