title: PostgreSQL: regex replace first level square brackets with curly braces
body: <p>I have data in a PostgreSQL column of type TEXT that I need to do some character replacement on.  Specifically I want to replace square brackets with curly braces.  The catch is that I only want to replace the brackets that are no more than two levels deep, if you include the main enclosing brackets.  These strings can be quite long so I think a regex is probably the way to go (<code>regexp_replace</code> function) but I'm no good with regex expressions.  Here's an example of one such value:</p>
  
  <pre><code>[0,0,0,[12,2],0,0,[12,[1,2,3]],12,0,[12,2,[2]],12,0,12,0,0]
  </code></pre>
  
  <p>So I would want this string to change to:</p>
  
  <pre><code>{0,0,0,{12,2},0,0,{12,[1,2,3]},12,0,{12,2,[2]},12,0,12,0,0}
  </code></pre>
  
  <p>Thanks in advance!</p>