import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "ContactMessageTransport[\\s\\S]*?Started(?:[^\\r\\n]*[\\r\\n]){3}";
final String string = " <getAllMessageQueueInfoResponse xmlns=\"http:abcd.com/MessageQueueAnalyticsAPI\">\n"
+ " <return>\n"
+ " <Entry xmlns:pogo=\"http://example.com/com/integration/services/messagequeueanalyticsservice\">\n"
+ " <pogo:AckCount>0</pogo:AckCount>\n"
+ " <pogo:DestinationID>0</pogo:DestinationID>\n"
+ " <pogo:ErrorCount>25</pogo:ErrorCount>\n"
+ " <pogo:ID>67</pogo:ID>\n"
+ " <pogo:Latest>2017-11-28T00:00:00-05:00</pogo:Latest>\n"
+ " <pogo:Name>ContactMessageTransport</pogo:Name>\n"
+ " <pogo:NotAckCount>0</pogo:NotAckCount>\n"
+ " <pogo:Oldest>2017-11-28T00:00:00-05:00</pogo:Oldest>\n"
+ " <pogo:RetryableErrorCount>31</pogo:RetryableErrorCount>\n"
+ " <pogo:SkippedCount>0</pogo:SkippedCount>\n"
+ " <pogo:Status>Started</pogo:Status>\n"
+ " <pogo:UnsentCount>212</pogo:UnsentCount>\n"
+ " </Entry>\n"
+ " <Entry xmlns:pogo=\"http://example.com/com/integration/services/messagequeueanalyticsservice\">\n"
+ " <pogo:AckCount>0</pogo:AckCount>\n"
+ " <pogo:DestinationID>0</pogo:DestinationID>\n"
+ " <pogo:ErrorCount>0</pogo:ErrorCount>\n"
+ " <pogo:ID>65</pogo:ID>\n"
+ " <pogo:Latest>2018-03-17T00:00:00-04:00</pogo:Latest>\n"
+ " <pogo:Name>Email</pogo:Name>\n"
+ " <pogo:NotAckCount>0</pogo:NotAckCount>\n"
+ " <pogo:Oldest>2018-03-17T00:00:00-04:00</pogo:Oldest>\n"
+ " <pogo:RetryableErrorCount>4</pogo:RetryableErrorCount>\n"
+ " <pogo:SkippedCount>0</pogo:SkippedCount>\n"
+ " <pogo:Status>Started</pogo:Status>\n"
+ " <pogo:UnsentCount>0</pogo:UnsentCount>\n"
+ " </Entry>";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html