title: Regex with recursive expression to match nested braces?
body: <p>I'm trying to match text like <code>sp { ...{...}... }</code>, where the curly braces are allowed to nest. This is what I have so far:</p>
  
  <pre><code>my $regex = qr/
  (                   #save $1
      sp\s+           #start Soar production
      (               #save $2
          \{          #opening brace
          [^{}]*      #anything but braces
          \}          #closing brace  
          | (?1)      #or nested braces
      )+              #0 or more
  )
  /x;
  </code></pre>
  
  <p>I just cannot get it to match the following text: <code>sp { { word } }</code>. Can anyone see what is wrong with my regex?</p>