const regex = /(?<host>[\w\-]+)(?=\.fully\.qualified\.domain\.name\.com).*?\b(?<ip>(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])))\b.*?(?<filename>[a-zA-Z]:\\(?:[^\\\/:*?"<>|\r\n]+\\)*[^\\\/:*?"<>|\r\n]*)(?=<br\s*\/?>)/gms;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<host>[\\w\\-]+)(?=\\.fully\\.qualified\\.domain\\.name\\.com).*?\\b(?<ip>(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])))\\b.*?(?<filename>[a-zA-Z]:\\\\(?:[^\\\\\\\/:*?"<>|\\r\\n]+\\\\)*[^\\\\\\\/:*?"<>|\\r\\n]*)(?=<br\\s*\\\/?>)', 'gms')
const str = `<td class="#ffffff" style=" " colspan="1">DNS Name:</td> <td class="#ffffff" style=" " colspan="1">comp-uter-123.fully.qualified.domain.name.com</td>
<snip few lines of crap>
<td class="#ffffff" style=" " colspan="1">IP:</td> <td class="#ffffff" style=" " colspan="1">10.0.0.10</td>
<snip like 150 lines of BS>
And then there's between 1 and maybe 50 of the below.
<h2>tcp/445/cifs</h2> <div class="clear"></div> <div style="box-sizing: border-box; width: 100%; background: #eee; font-family: monospace; padding: 20px; margin: 5px 0 20px 0;"> <br> Path : C:\\Users\\username\\dir1\\dir2\\dir3\\dir4\\filename.exe<br> Installed version : 1.2.12<div class="clear"></div>`;
// 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