title: Regular expression to extract argument in a LaTeX command
body: <p>I have a large LaTeX document where I have defined a macro like this:</p>
  
  <pre><code>\newcommand{\abs}[1]{\left|#1\right|}
  </code></pre>
  
  <p>I want to get rid of it by replacing in all the document <code>\abs{...}</code> by <code>\left|...\right|</code>, so I am thinking in a regular expression. I am familiar with their basics but I do not know how to find the bracket that closes the expression, given that the following situations are possible: </p>
  
  <ol>
  <li><code>\abs{(2+x)^3}</code> </li>
  <li><code>\abs{\frac{2}{3}}</code></li>
  <li><code>\abs{\frac{2}{\sin(2\abs{x})}}</code></li>
  </ol>
  
  <p>What I have been able to do for the moment is <code>\\abs\{([^\}]*)\}</code> and then replace as <code>\left\1\right|</code>but it is only able to deal with the pieces of code of the first kind only.</p>
  
  <p>By the way, I am using the TeXstudio regular expression engine.</p>