import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[\\r\\n]+(?<_KEY_1>[^\\n:]+):(?<_VAL_1>[^\\r\\n]+)";
final String string = "<plugin_output>\n"
+ "Path : /opt/AdoptOpenJRE/jdk8u332-b09-jre/\n"
+ "Version : 1.8.0_332\n"
+ "Binary Location : /opt/AdoptOpenJRE/jdk8u332-b09-jre/bin/java\n"
+ "Details : This Java install appears to be Java Runtime Environment, since\n"
+ "\"jre\" was found in the installation path and javac was not found\n"
+ "(medium confidence).\n"
+ "This Java install may be Oracle Java or OpenJDK Java due to\n"
+ "\"org.openjdk.java.util\" in the binary (low confidence).\n"
+ "Detection Method : \"find\" utility\n"
+ "</plugin_output>\n\n\n"
+ "Variation 2:\n\n"
+ "<plugin_output>\n"
+ "Path : /HP/hpoa/CADE2/HP/nonOV/openadaptor/1_6_5/classes/oa_jdk14_classes.jar\n"
+ "Version : 1.1.0\n"
+ "JMSAppender.class association : Found\n"
+ "JdbcAppender.class association : Found\n"
+ "JndiLookup.class association : Not Found\n"
+ "Method : MANIFEST.MF dependency\n"
+ "</plugin_output>\n\n\n"
+ "Variation 3:\n\n"
+ "<plugin_output>\n"
+ "Path : /opt/IBM/WebSphere855/AppServer/java_1.7_64/\n"
+ "Installed version : 7.0\n"
+ "Fixed version : 7.0.11.5\n\n"
+ "Path : /opt/IBM/WebSphere855/AppServer.old/java_1.7_64/\n"
+ "Installed version : 7.0\n"
+ "Fixed version : 7.0.11.5\n\n"
+ "Path : /opt/IBM/WebSphere855/AppServer.gagan/java_1.7_64/\n"
+ "Installed version : 7.0\n"
+ "Fixed version : 7.0.11.5\n\n"
+ "Path : /opt/IBM/InstallationManager/eclipse/jre_7.0.100001.20170309_1301/\n"
+ "Installed version : 7.0\n"
+ "Fixed version : 7.0.11.5\n"
+ "</plugin_output>\n\n";
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