const regex = /^(?<timestamp>\d+-\d+-\d+T\d+:\d+:\d+\.\d+([+-])\d+:\d+)\s+\[(?<severity>\w+)\](?<message>.*(?:\n(?!\d+-\d+-\d+T).*)*)$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?<timestamp>\\d+-\\d+-\\d+T\\d+:\\d+:\\d+\\.\\d+([+-])\\d+:\\d+)\\s+\\[(?<severity>\\w+)\\](?<message>.*(?:\\n(?!\\d+-\\d+-\\d+T).*)*)$', 'gm')
const str = `2022-06-27T15:22:35.506+00:00 [Info] MSAT starting with 60000 tick ...
2022-06-27T15:22:35.506+00:00 [Info] pram[:9999] starting ...
2022-06-27T15:22:35.508+00:00 [Info] New settings received:
{"indexer.settings.compaction.days_of_week":"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday","indexer.settings.compaction.interval":"00:00,00:00","indexer.settings.compaction.compaction_mode":"circular","indexer.settings.log_level":"info","indexer.settings.persisted_snapshot.interval":5000,"indexer.settings.compaction.min_frag":30,"indexer.settings.inmemory_snapshot.interval":200,"indexer.settings.max_cpu_percent":0,"indexer.settings.storage_mode":"forestdb","indexer.settings.recovery.max_rollbacks":5,"indexer.settings.memory_quota":1073741824,"indexer.settings.compaction.abort_exceed_interval":false}
2022-06-27T15:22:35.508+00:00 [Info] PROJ[:9999] settings notifier from metakv
`;
// 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