title: Regexp to check if parentheses are balanced
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/133601/can-regular-expressions-be-used-to-match-nested-patterns">Can regular expressions be used to match nested patterns?</a>  </p>
  </blockquote>
  
  
  
  <p>I am writing a regexp to check if the input string is a correct arithmetic expression. The problem is checking if there are enough opening and closing parentheses.</p>
  
  <p>Expressions:</p>
  
  <ol>
  <li><p>(1)</p></li>
  <li><p>(((1)</p></li>
  <li><p>((1))))</p></li>
  </ol>
  
  <p>I think lookahead and lookbehind are useful here but for now I could check only one kind. I'm using Java, if it matters.</p>