regex Java正则表达式只匹配签名中的方法名称
我有一个表示方法签名的字符串列表。例如:
public String someMethod(String parameter)
public static void someAnotherMethod(double doubleParam, List<String> stringList)
通过使用以下正则表达式(linkhttps://regex101.com/r/TwRRbp/1),我可以获得方法名和参数:
\w+\(.*\)
最后,我得到以下信息:
someMethod(String parameter)
someAnotherMethod(double doubleParam, List<String> stringList)
但我只需要方法名。我想我需要把重点放在开头的括号上
# 1 楼答案
使用
见proof
解释