title: Regex that Will Match a Java Method Declaration
body: <p>I need a Regex that will match a java method declaration. I have come up with one that will match a method declaration, but it requires the opening bracket of the method to be on the same line as the declaration. If you have any suggestions to improve my regex or simply have a better one then please submit an answer.</p>
  
  <p>Here is my regex: <code>"\w+ +\w+ *\(.*\) *\{"</code></p>
  
  <p>For those who do not know what a java method looks like I'll provide a basic one:</p>
  
  <pre><code>int foo()
  {
  
  }
  </code></pre>
  
  <p>There are several optional parts to java methods that may be added as well but those are the only parts that a method is guaranteed to have.</p>
  
  <p>Update:
  My current Regex is <code>"\w+ +\w+ *\([^\)]*\) *\{"</code> so as to prevent the situation that Mike and adkom described.</p>