use strict;
my $str = '<plugin_output>
Path : /opt/AdoptOpenJRE/jdk8u332-b09-jre/
Version : 1.8.0_332
Binary Location : /opt/AdoptOpenJRE/jdk8u332-b09-jre/bin/java
Details : This Java install appears to be Java Runtime Environment, since
"jre" was found in the installation path and javac was not found
(medium confidence).
This Java install may be Oracle Java or OpenJDK Java due to
"org.openjdk.java.util" in the binary (low confidence).
Detection Method : "find" utility
</plugin_output>
Variation 2:
<plugin_output>
Path : /HP/hpoa/CADE2/HP/nonOV/openadaptor/1_6_5/classes/oa_jdk14_classes.jar
Version : 1.1.0
JMSAppender.class association : Found
JdbcAppender.class association : Found
JndiLookup.class association : Not Found
Method : MANIFEST.MF dependency
</plugin_output>
Variation 3:
<plugin_output>
Path : /opt/IBM/WebSphere855/AppServer/java_1.7_64/
Installed version : 7.0
Fixed version : 7.0.11.5
Path : /opt/IBM/WebSphere855/AppServer.old/java_1.7_64/
Installed version : 7.0
Fixed version : 7.0.11.5
Path : /opt/IBM/WebSphere855/AppServer.gagan/java_1.7_64/
Installed version : 7.0
Fixed version : 7.0.11.5
Path : /opt/IBM/InstallationManager/eclipse/jre_7.0.100001.20170309_1301/
Installed version : 7.0
Fixed version : 7.0.11.5
</plugin_output>
';
my $regex = qr/[\r\n]+(?<_KEY_1>[^\n:]+):(?<_VAL_1>[^\r\n]+)/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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 Perl, please visit: http://perldoc.perl.org/perlre.html