title: Find matching bracket with Regex
body: <p>The input is a string representing a list of elements. </p>
  
  <p>A list is defined as an open curly <code>{</code> followed by 0 or more elements separated by whitespace followed by a closed curly <code>}</code>.</p>
  
  <p>An element is either a literal or a list of elements.</p>
  
  <p>A literal is a succession of non-whitespace characters. If an element contains a curly bracket, it must be escaped with a backslash : <code>\{</code> and <code>\}</code>. (Or you could assume curlies are not allowed inside literals, for simplicity)</p>
  
  <p>Example:</p>
  
  <pre><code>"{abc { def ghi } 7 { 1 {2} {3 4} } {5 6} x\{yz \}foo }"
  </code></pre>
  
  <p>No curlies inside literals:</p>
  
  <pre><code>"{abc { def ghi } 7 { 1 {2} {3 4} } {5 6} xyz foo }"
  </code></pre>
  
  <p>(This is a simplified definition of a Tcl list.)</p>
  
  <p>What I want to know is: can the input be split into the elements of the outermost loop using regex?</p>
  
  <p>Expected output: </p>
  
  <pre><code>abc
  { def ghi }
  7
  { 1 {2} {3 4} }
  {5 6}
  x{yz
  }foo
  </code></pre>
  
  <p>The real question is: can this be done with a Regex? </p>
  
  <p>I'm most interested in the .NET flavour, but will accept any answers.</p>
  
  <p>I'll post my own assumption in an answer, and see if it's validated or destroyed.</p>