const regex = new RegExp('(\\w+\\s+\\w+\\s+[\\d:\\s]+[A-Z]{3}\\s+\\d{4})[\\s\\S]+?((?:\\w+)\\s+(?:[0-9.]+))\\s+(?:((?:\\w+)\\s*(?:[0-9.]+)))?\\s+(?:((?:\\w+)\\s*(?:[0-9.]+)))?\\s*(?:((?:\\w+)\\s+(?:[0-9.]+)))?\\s*(?:((?:\\w+)\\s*(?:[0-9.]+)))?', 'g')
const str = `Mon Feb 1 09:12:41 GMT 2016
Rotating fax log files:
Doing login accounting:
total 688.31
example 401.12
_mbsetupuser 287.10
root 0.05
admin 0.04
-- End of monthly output --
Tue Feb 16 14:27:21 GMT 2016
Rotating fax log files:
Doing login accounting:
total 0.00
-- End of monthly output --
Thu Mar 3 09:37:31 GMT 2016
Rotating fax log files:
Doing login accounting:
total 377.92
example 377.92
-- End of monthly 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