I am trying to split the below multiline string by scanner. I want to split the lines starting with "A|"
Input
A|14|23|656
B|15|ga|a
A|11|424|6262
Output
Group
A|14|23|656
B|15|ga|a
Group
A|11|424|6262
I have tried scanner as below.
public static void main(String[] args) {
String abcd = "A|14|23|656\r\nB|15|ga|a\r\nA|11|424|6262";
try (final Scanner scan = new Scanner(abcd)) {
scan.useDelimiter("^A\\|");
while (scan.hasNext()) {
System.out.println("Group");
System.out.println("A|" + scan.next());
}
}
}
Actual: It is just considering the matching A| on the first line not on other lines.
Group
A|14|23|656
B|15|ga|a
A|11|424|6262