0

I have something like the below line of String.

String log = "Daily batch run has been completed Status = Success at the first attempt Logging out Admin...OK"
String batchOutput = "";

I need to extract only "Success at the first attempt".

I have tried out the below.

Pattern pattern = Pattern.compile("Status = (.*)");
Matcher matcher = pattern.match(log);

if (matcher.find()) {

batchOutput = matcher.group(1);
System.out.println(batchOutput) // This displays Status = Success at the first attempt Logging out Admin...OK"
}

However, I need to extract out only "Status = Success at the first attempt"

Again I took a substring of the batchOutput string

batchOutput = batchOutput.substring(0, batchOutput.indexOf("L")).trim(); // This displays only "Status = Success at the first attempt"

I believe that instead of using the substring method, this can be extracted out by using valid regex expression.

Could I get some help on this please? }

Sanga
  • 1
  • 1
  • So, you want to use `"Status = ([^L]*)"`, right? See linked thread, scroll to *a certain single character or a set of characters* – Wiktor Stribiżew Apr 14 '20 at 11:41
  • ^(?:Daily batch run has been completed Status = (Success at the first attempt) Logging out Admin...OK)$. If it matches you will have the string in the first group. – Juan Apr 14 '20 at 11:45

0 Answers0