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:
re.compile(regex).groups
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.
Thanks for any suggestions!