import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?=[^P]*(?:ParNew|P.*ParNew|PSYoungGen|DefNew)).*?(?P<ParNew_before_1>\\d+)K->(?P<ParNew_after_1>\\d+)K\\((?P<young_heap_size>\\d+)K\\), (?P<par_new_duration>\\d+\\.\\d+) secs\\] (?P<ParNew_before_2>\\d+)K\\->(?P<ParNew_after_2>\\d+)K\\((?P<total_heap_size>\\d+)";
final String string = "146372.273: [GC146372.274: [ParNew: 378633K->88155K(419456K), 0.0313803 secs] 9893391K->9602913K(12478080K), 0.0320299 secs] [Times: user=0.32 sys=0.01, real=0.03 secs] \n\n"
+ "2017-05-12T10:35:46.076+0000: 2.799: [GC2017-05-12T10:35:46.076+0000: 2.800: [ParNew: 409024K->51072K(460096K), 0.3273966 secs] 409024K->121051K(2046080K), 0.3275292 secs] [Times: user=0.31 sys=0.07, real=0.33 secs] \n\n\n\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