title: Regex to remove outer brackets
body: <p>I have been using this <code>/\(\s*([^)]+?)\s*\)/</code> regex to remove outer brackets with PHP preg_replace function (Read more in my previous question <a href="https://stackoverflow.com/questions/10765699/regex-to-match-any-character-except-trailing-spaces">Regex to match any character except trailing spaces</a>).</p>
  
  <p>This works fine when there is only one pair of brackets, but problem is when there is more, for example <code>( test1 t3() test2)</code> becomes <code>test1 t3( test2)</code> instead <code>test1 t3() test2</code>.</p>
  
  <p>I am aware of regex limitations, but it would be nice if I could just make it not matching anything if there is more then one pair of brackets.</p>
  
  <p>So, example behavior is good enough:</p>
  
  <p><code>( test1 test2 )</code> => <code>test1 test2</code></p>
  
  <p><code>( test1 t3() test2 )</code> => <code>(test1 t3() test2)</code></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I would like to keep trimming trailing white spaces inside removed brackets.</p>