const regex = /[\r\n]+(?<_KEY_1>[^\n:]+):(?<_VAL_1>[^\r\n]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[\\r\\n]+(?<_KEY_1>[^\\n:]+):(?<_VAL_1>[^\\r\\n]+)', 'gm')
const 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>
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions