const regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \S+ \(\S+\) - flush done sketch={flushed=(\d+) total=(\d+) pruned=(\d+)} num_org_metric=\d+ since_ms=(\d+)ms dt=[-+]?([0-9]*(\.[0-9]*)?[a-z]+)+/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} \\S+ \\(\\S+\\) - flush done sketch={flushed=(\\d+) total=(\\d+) pruned=(\\d+)} num_org_metric=\\d+ since_ms=(\\d+)ms dt=[-+]?([0-9]*(\\.[0-9]*)?[a-z]+)+', 'gm')
const str = `2018-03-05 22:52:52 INFO (app.go:391) - flush done sketch={flushed=264557 total=57979680 pruned=295} num_org_metric=448 since_ms=10964ms dt=2.2392s
2018-03-05 22:53:01 INFO (app.go:391) - flush done sketch={flushed=171045 total=57954960 pruned=253} num_org_metric=448 since_ms=9377ms dt=1.616403s
2018-03-05 22:53:10 INFO (app.go:391) - flush done sketch={flushed=190064 total=57933000 pruned=297} num_org_metric=448 since_ms=9366ms dt=982.968ms
2018-03-05 22:53:20 INFO (app.go:391) - flush done sketch={flushed=153243 total=57932520 pruned=89} num_org_metric=448 since_ms=9908ms dt=891.573ms`;
// 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