import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:\\S+\\s){27,27}(?:status:\\s+(?<status>\\d+))?";
final String string = "Property(S): PrimaryVolumeSpaceAvailable = 0\n"
+ "Property(S): PrimaryVolumeSpaceRequired = 0\n"
+ "Property(S): PrimaryVolumeSpaceRemaining = 0\n"
+ "Property(S): ProductToBeRegistered = 1\n"
+ "MSI (s) (24:7C) [21:56:44:998]: Note: 1: 1707 \n"
+ "MSI (s) (24:7C) [21:56:44:998]: Product: VetLab Station -- Installation operation completed successfully.\n\n"
+ "MSI (s) (24:7C) [21:56:45:001]: Windows Installer installed the product. Product Name: VetLab Station. Product Version: 4.35.72. Product Language: 1033. Manufacturer: IDEXX Laboratories, Inc.. Installation success or error status: 0.\n\n"
+ "MSI (s) (24:7C) [21:56:45:002]: Value of RebootAction property is \n"
+ "MSI (s) (24:7C) [21:56:45:002]: Windows Installer requires a system restart. Product Name: VetLab Station. Product Version: 4.35.72. Product Language: 1033. Manufacturer: IDEXX Laboratories, Inc.. Type of System Restart: 1. Reason for Restart: 0.";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (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