我有一个包含“n”个复杂函数的类,如下所示:
public class Foo {
public String getSmt(String param, Foo foo) {
try {
if (smtIsTrue()) {
Thread mThread = new Thread(new Runnable(){
@Override
public void run() {
// Here I do something
}
}).start();
} else if (other()) {
if (isExisted()) {
execute();
}
}
} catch (Exception e) {
throw new Exception(e.getMessage());
} finally {
doSmt();
}
}
public String otherGetSmt(String param, Foo foo) {
try {
if (smtIsTrue()) {
Thread mThread = new Thread(new Runnable(){
@Override
public void run() {
// Here I do something
}
}).start();
} else if (other()) {
if (isExisted()) {
execute();
}
}
} catch (Exception e) {
throw new Exception(e.getMessage());
} finally {
doSmt();
}
}
}
我想使用 Regex 获取两个函数的内容。你能这样吗? 这个我试过了
(public|protected|private|static|\s) +[\w\<\>\[\], ]+\s+(\w+) *\([^\)]*\) *(\{?|[^;]) .*\{((\s|.)*)\}
但我工作得不好。
最佳答案
使用这个。 <强> DEMO
\{((\s*?.*?)*?)*\}
关于java - 获取函数内容(大括号之间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27716305/