title: How to write a recursive regex that matches nested parentheses?
body: <p>I am trying to write a regexp which matches nested parentheses, e.g.:</p>
  
  <pre><code>"(((text(text))))(text()()text)(casual(characters(#$%^^&amp;&amp;#^%#@!&amp;**&amp;#^*!@#^**_)))"
  </code></pre>
  
  <p>A string like this should be matched, cause all the nested parentheses are closed, instead:</p>
  
  <pre><code>"(((text)))(text)(casualChars*#(!&amp;#*(!))"
  </code></pre>
  
  <p>Should not, or better, should match at least the first "(((text)))(text)" part.</p>
  
  <p>Actually, my regexp is:</p>
  
  <pre><code> $regex = '/( (  (\() ([^[]*?)  (?R)?  (\))  ){0,}) /x';
  </code></pre>
  
  <p>But it does not work properly as I am expecting. How to fix that? Where am I wrong? Thanks!</p>