import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "GC.*?([\\d.]+)(?= secs\\](?: \\[Time|$))";
final String string = "2014-12-04T03:44:55.059+0000: 3155402.861: [GC 3155402.861: [ParNew: 52663K->161K(59008K), 0.0037300 secs] 81475K->28973K(104200K), 0.0038550 secs] [Times: user=0.01 sys=0.01, real=0.01 secs]\n\n"
+ "2014-12-04T04:26:31.955+0000: 3157899.757: [GC 3157899.757: [ParNew: 52641K->161K(59008K), 0.0014220 secs] 81453K->28973K(104200K), 0.0015160 secs] [Times: user=0.01 sys=0.01, real=0.00 secs]\n\n"
+ "2014-12-04T05:08:48.764+0000: 3160436.567: [GC 3160436.567: [ParNew: 52641K->163K(59008K), 0.0028550 secs] 81453K->28975K(104200K), 0.0029850 secs]";
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