I need regex (named in code myRegex) which will match all functions (function1, function2, function3).
public static void main(String[] args) {
String template = "f[0-9]"; // like f1, f2 etc
String myRegex = "fun\\((" + template + "*)\\)"; //todo what regex?
Pattern myPattern = Pattern.compile(myRegex);
String function1 = "fun(f1)";
String function2 = "fun(f1,f9)"; //myRegex don't match
String function3 = "fun(f1,f9,f4)"; // myRegex don't match
List<String> functions = Lists.asList(function1, function2, function3);
for (String function : functions) {
Matcher matcher = myPattern.matcher(function);
while (matcher.find())
{
System.out.println(function + " match!");//works only for function1
}
}
}
Elements in brackets must be seperated by comma (,). It must work for other funcions with many arguments like :function4 = "fun(f1,f9,f4,f5,f7)";