title: PHP throws PREG_BACKTRACK_LIMIT_ERROR error but regex works in javascript, why?
body: <p>Here's the regular expression:</p>
  
  <pre><code>([A-Z]+(?:(?:[\w\d@#$%&amp;;,\+\.\*!-]+)?\s?(?![a-z&amp;;]+\s)){1,})\s(&lt;span class="label label-inverse"&gt;.*?&lt;/span&gt;)
  </code></pre>
  
  <p>This will match a string such as this:</p>
  
  <pre><code>&lt;p&gt;Buy Apple &lt;span class="label label-inverse"&gt;AAPL - NYSE&lt;/span&gt; at or under $100 per share.&lt;/p&gt;
  </code></pre>
  
  <p>When tested in a javascript regex tester such as regexpal, it works as expected. However, the PHP preg_replace function returns null with the error PREG_BACKTRACK_LIMIT_ERROR.</p>
  
  <pre><code>$string = preg_replace('~([A-Z]+(?:(?:[\w\d@#%&amp;!;,\+\.\*\$-]+)?\s?(?![a-z&amp;;]+\s)){1,})\s(&lt;span class="label label-inverse"&gt;.*?&lt;/span&gt;)~i', '&lt;strong&gt;$1&lt;/strong&gt; $2', $string);
  </code></pre>
  
  <p>Why is this? Can anyone explain what is wrong with the regex in PHP and how to correct it so it functions as it does in javascript?</p>