public static Long getLastDropIdFromOutput(OutputCapture outputCapture) { Pattern compile = Pattern.compile("Drop id: ([\\d]+)"); Matcher matcher = compile.matcher(outputCapture.toString()); String dropId = null; while (matcher.find()) { dropId = matcher.group(1); } return Long.valueOf(dropId); }