I want to parse a multiline text, so I wrote something like this:
String text = "[timestamp1] INFO - Message1 \r\n"
+ "[timestamp2] ERROR - Message2 \r\n"
+ "[timestamp3] INFO - Message3 \r\n"
+ "Message3_details1......... \r\n"
+ "Message3_details2 ......... \r\n";
String regex = "\\[(.*)\\] (.*) - (.*)";
Pattern p = Pattern.compile(regex, Pattern.DOTALL);
Matcher m = p.matcher(text);
while (m.find()) {
System.out.println("G1: " + m.group(1));
System.out.println("G2: " + m.group(2));
System.out.println("G3: " + m.group(3));
System.out.println();
}
What I want to get is this:
G1: timestamp1
G2: INFO
G3: message1
G1: timestamp2
G2: ERROR
G3: message2
G1: timestamp3
G2: INFO
G3: message3
message_details1....
message_details2...
But what I get is like this:
G1: timestamp1] INFO - Message1
[timestamp2] ERROR - Message2
[timestamp3
G2: INFO
G3: Message3
Message3_details1........
Message3_details2........
I'm not able to solve that even with Google's help.