使用ultrasx检测有效的方法调用

时间:2013-09-15 05:53:29

标签: java regex

    if (word.matches("^[a-zA-Z_](.)][a-zA-Z_]*$") ) {
          System.out.println(word);
    }

我需要编写方法来识别类中的方法调用。  例如。 A =新A();     a.call();

我需要在我的班级中找到a.call()表单。

1 个答案:

答案 0 :(得分:0)

  • [a-zA-Z_]只匹配一个字符。附加*+以匹配多个字符。
  • .匹配任何字符。转义.以匹配文字点。

尝试使用正则表达式:

"[a-zA-Z_]\\w*\\.[a-zA-Z_]\\w*\\(.*?\\)"

示例:

import java.util.regex.*;

class T {
    public static void main(String[] args) {
        String word = "A a =new A(); a.call();";
        Pattern pattern = Pattern.compile("[a-zA-Z_]\\w*\\.[a-zA-Z_]\\w*\\(.*?\\)");
        Matcher matcher = pattern.matcher(word);
        while (matcher.find()) {
            System.out.println(matcher.group());
        }
    }
}