title: Matching balanced parenthesis in Ruby using recursive regular expressions like perl
body: <p>I have been looking for a way to match balanced parenthesis in a regex and found a way in Perl, that uses a recursive regular expression:</p>
  <pre><code>my $re;
  $re = qr{
             \(
                (?:
                   (?&gt; [^()]+ )       # Non-parens without backtracking
                   |
                   (??{ $re })        # Group with matching parens
                )*
             \)
           }x;
  </code></pre>
  <p>from the <a href="http://perldoc.perl.org/perlre.html#Regular-Expressions" rel="noreferrer">perl regular expression site</a>
  .</p>
  <p>Is there a way to do this in Ruby or a similar language?</p>
  <p><em><strong>UPDATE</strong></em>:</p>
  <p>For those interested here are some interesting links:</p>
  <p><a href="http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt" rel="noreferrer">Oniguruma manual</a> - from Sawa's answer.</p>
  <p><a href="http://media.pragprog.com/titles/ruby3/ruby3_extract_regular_expressions.pdf" rel="noreferrer">Pragmatic Programmers' Ruby 1.9 Regular Expressions Sample Chapter</a></p>