Regex to match a Java method signature
- by nitesh
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.