Wow! .. Thanks, trash! It really works ... in Perl. But not in PCRE. So, the question mutates to "What is the difference between matching Perl regular expressions and PCRE?"
And voila! Answer:
The difference between recursion and Perl
In PCRE (like Python, but unlike Perl), a recursive subpattern call is
always treated as an atomic group. That is, once it has matched some of
the subject string, it is never re-entered, even if it contains untried
alternatives and there is a subsequent matching failure.
Therefore, we just need to change two subpatterns:
/ \A ( (?: \( (?1) \) | [^()]* )+ ) \Z /x
Thank!
source
share