title: Regular expressions with matching brackets
body: <p>I'm trying to extract specific hard coded variables from C source code. My remaining problem is that I'd like to parse array initialisation, for example:</p>
  
  <pre><code>#define SOMEVAR { {T_X, {1, 2}}, {T_Y, {3, 4}} }
  </code></pre>
  
  <p>It's enough to parse this example into "{T_X, {1, 2}}" and "{T_Y, {3, 4}}", since it's then possible to recurse to get the full structure. However, it needs to be sufficiently general so as to be able to parse any user defined types.</p>
  
  <p>Even better would be a list of regular expressions that can be used to extra values from general C code constructs like <code>#define</code>, enums and global variables.</p>
  
  <p>The C code is provided to me, so I have no control over it. I'd rather not write a function that parses it a character at a time. However, it'd be OK to have a sequence of regular expressions.</p>
  
  <p>This is not a problem of getting files into MATLAB or basic regular expressions. I'm after a specific regular expression that preserves groupings by brackets.</p>
  
  <p>EDIT: Looks like regular expressions don't do recursion or arbitrarily deep matches. According to <a href="https://stackoverflow.com/questions/546433/regular-expression-to-match-outer-brackets">here</a> and <a href="https://stackoverflow.com/questions/524548/regular-expression-to-detect-semi-colon-terminated-c-for-while-loops">here</a>.</p>