需要用到hutool工具包

测试用例代码,输出异常栈前3行代码:

1
2
3
4
5
6
7
8
9
10
11
12
String str = "java.lang.StringIndexOutOfBoundsException: String index out of range: 299\n" +
"\tat java.lang.String.substring(String.java:1963)\n" +
"\tat com.zenxton.exception.BusinessException.test1(BusinessException.java:32)\n" +
"\tat com.zenxton.exception.BusinessException.test2(BusinessException.java:45)\n" +
"\tat com.zenxton.exception.BusinessException.test2(BusinessException.java:45)\n" +
"\tat com.zenxton.exception.BusinessException.test2(BusinessException.java:45)\n" +
"\tat com.zenxton.exception.BusinessException.test2(BusinessException.java:45)\n" +
"\tat com.zenxton.exception.BusinessException.test2(BusinessException.java:45)\n" +
"\tat com.zenxton.exception.BusinessException.main(BusinessException.java:20)";

String resultExtractMulti = ReUtil.extractMulti("([\\S\\s]*?\n)([\\S\\s]*?\n)([\\S\\s]*?\n)", str, "$1-$2-$3");
System.out.println(resultExtractMulti);

upload successful