import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<Item TimeStamp=\"(?<timestamp>\\d*:\\d*:\\d*.\\d*)\"[[:blank:]]Duration=\"(?<duration>\\d*:\\d*:\\d*.\\d*)\"[[:blank:]]Line=\"(?<scriptline>\\d*)\"[[:blank:]]File=\"(?<scriptfilename>.*)\"[[:blank:]]Command=\"(?<command_name>\\w*)\"[[:blank:]]Type=\"(?<severity>\\w*)\">(?<message>[\\D]*)\\t(?<time>\\d*.\\d*)<\\/Item>";
final String string = "<Item TimeStamp=\"00:33:12.88\" Duration=\"00:00:00.00\" Line=\"87\" File=\"all_test_v2.tws\" Command=\"print\" Type=\"Info\">Loading Result screen time is: -1</Item>\n\n"
+ "<Item TimeStamp=\"00:32:32.10\" Duration=\"00:00:00.00\" Line=\"40\" File=\"all_test_v2.tws\" Command=\"print\" Type=\"Info\">Loading Search screen time 0.8045754</Item>\n\n"
+ "<Item TimeStamp=\"00:32:31.16\" Duration=\"00:00:00.00\" Line=\"28\" File=\"all_test_v2.tws\" Command=\"print\" Type=\"Info\">Loading Splash screen time is: 4.3964327</Item>\n";
final Pattern pattern = Pattern.compile(regex);
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