title: Count subpatterns in PHP PCRE RegEx
body: <p>I want to implement something like "editor for regular expressions". It is for power users of my PHP application. The problem is, I need something like "reflection" for the regular expression (to be more precise, for any given regular expression) to find out how many subpatterns it contains. In Python, I simply type:</p>
  
  <pre><code>re.compile(regex).groups
  </code></pre>
  
  <p>How to implement that in PHP? It would be also nice to be able safely know, if the expression is even able to compile. In Python, there are exceptions raised and it's easy to handle them. PHP shoots my application without any alerts, or produces some warnings/errors, which can't be caught.</p>
  
  <p>Thanks for any suggestions!</p>