I have defined following pattern to parse our own custom for a function which is: <functionName>[<arg1>, <arg2>, ..] and the pattern is:
([a-zA-Z0-9]+)\\[(([a-zA-Z0-9]+)(,([a-zA-Z0-9])+)*?)*?\\]
Now when I run this against an example function: properCase[ARG1,ARG2], I get the following output:
Total matches are: 5
Group number 0is: properCase[ARG1, ARG2]
Group number 1is: properCase
Group number 2is: ARG1
Group number 3is: ARG1
Group number 4is: ,ARG2
Code:
Matcher m = funcPattern.matcher("properCase[ARG1, ARG2]");
System.out.println("Match found: " + m.matches());
System.out.println("Total matches are: " + m.groupCount());
if (m.matches())
{
for (int index= 0 ; index < m.groupCount(); index++)
{
System.out.println("Group number "+ index + "is: " +m.group(index));
}
}
How can I only extract out the function name (as group 1) and argument list (as group 2, group 3)? I am not able to eliminate the , from the group.