更新答案
使用正则表达式
String pattern = "([\\s\\S]*?)(!!!Error deploying file)";
上面的图案的说明。
- *? - 零点和无限时间之间匹配单个字符
- \ S - 匹配任何空白字符
- \ S - 匹配任何非空白字符
实施例的代码:
String line = "!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountCurrInCo.sql at 22-JUL-16 08:07:Chathura aBhanakana1!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA !!!Error deploying file order\\POST";
String pattern = "([\\s\\S]*?)(!!!Error deploying file)";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
while (m.find()) {
String str = m.group(1);
if(str != null && !str.isEmpty()){
System.out.println("Found value: " + str);
}
}
输出
- 找到的值:order \ POST_ORDER_UpdateTaxAmountCurrInCo.sql at 22 -JUL-16 08:07:Chathura aBhanakana1
- 实测值: 顺序\ POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA
Check output here
使用分割法
示例代码:
String line = "!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountCurrInCo.sql at 22-JUL-16 08:07:Chathura aBhanakana1!!!Error deploying file order\\POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA !!!Error deploying file order\\POST";
for (String retval: line.split("!!!Error deploying file")){
System.out.println(retval);
}
产量:
1) order\POST_ORDER_UpdateTaxAmountCurrInCo.sql at 22-JUL-16 08:07:Chathura aBhanakana1
2) order\POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA
3) order\POST
Check output here
什么是你想在这里实现? – NAIT
以获取“!!!错误部署文件”文本字段之间的文本。 –
把'。*?'放在'()' –