java正则表达式查找方法调用 9 月,3 周 Questions & Answers 4659 我想在给定的代码中找到任何方法调用。所以我用分号分隔代码。所以最后,我感兴趣的是找到在给定代码中被调用的方法的名称。我需要一个正则表达式来匹配方法调用模式。请帮忙
# 1 楼答案 File f=new File("Sample.java"); //Open a file String s; FileReader reader=new FileReader(f); BufferedReader br=new BufferedReader(reader); //Read file while((s=br.readLine())!=null){ String regex="\\s(\\w+)*\\(((\\w+)*?(,)?(\\w+)*?)*?\\)[^\\{]"; Pattern funcPattern = Pattern.compile(regex); Matcher m = funcPattern.matcher(s); //Matcher is used to match pattern with string if(m.find()){ System.out.printf(group(0)); } }
# 1 楼答案
# 2 楼答案
我认为这个可以,但它与参数的次要正则表达式不匹配: