Regex to match a Java method signature
        Posted  
        
            by nitesh
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by nitesh
        
        
        
        Published on 2010-06-09T15:12:21Z
        Indexed on 
            2010/06/12
            11:22 UTC
        
        
        Read the original article
        Hit count: 234
        
I am having this particular requirement where a method has to be identified by different regular expressions for different components. For example, there need to be a regex for return parameter, one for method name, one for argument type and one for argument name. I was able to come up with an expression till this step as follows -
([^,]+) ([^,]+)\((([^,]+) ([^,]+))\)
It works well for a method signature like -
ReturnType foo(Arg parameter) The regular expression identifies ReturnType, foo, Arg and parameter separately.
Now the problem is that a method can have no/one/multiple arguments separated by commas. I am not able to get a repeating expression for this. Help will be appreciated.
© Stack Overflow or respective owner