Updated answer
Using regex
String pattern = "([\\s\\S]*?)(!!!Error deploying file)";
Explanation of above pattern.
- *? - match a single character between zero and unlimited times
- \s - match any white space character
- \S - match any non-whitespace character
Example code :
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 );
}
}
Output
- Found value: order\POST_ORDER_UpdateTaxAmountCurrInCo.sql at
22-JUL-16 08:07:Chathura aBhanakana1
- Found value:
order\POST_ORDER_UpdateTaxAmountChathura aBhanakana1AAAAA
Check output here
Using split method
Example code :
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);
}
Output :
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