const regex = /^(\w{3}\s{1}\w{3}\s{1}\d{2}\s{1}\d{2}\:\d{2}\:\d{2}\s{1}\d{4})?((\r||.|\n)*)(?=(\w{3}\s{1}\w{3}\s{1}\d{2}\s{1}\d{2}\:\d{2}\:\d{2}\s{1}\d{4}))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\w{3}\\s{1}\\w{3}\\s{1}\\d{2}\\s{1}\\d{2}\\:\\d{2}\\:\\d{2}\\s{1}\\d{4})?((\\r||.|\\n)*)(?=(\\w{3}\\s{1}\\w{3}\\s{1}\\d{2}\\s{1}\\d{2}\\:\\d{2}\\:\\d{2}\\s{1}\\d{4}))', 'gm')
const str = `Tue Sep 14 08:57:47 2021
Thread 1 advanced to log sequence 186 (LGWR switch)
Current log# 2 seq# 186 mem# 0: D:\\ORADB\\DV1\\REDO02A.LOG
Current log# 2 seq# 186 mem# 1: H:\\ORADB\\DV1\\REDO02B.LOG
Tue Sep 14 09:07:40 2021
Thread 1 advanced to log sequence 187 (LGWR switch)
Current log# 3 seq# 187 mem# 0: D:\\ORADB\\DV1\\REDO03A.LOG
Current log# 3 seq# 187 mem# 1: H:\\ORADB\\DV1\\REDO03B.LOG
Tue Sep 14 09:22:09 2021
Thread 1 advanced to log sequence 188 (LGWR switch)
Current log# 4 seq# 188 mem# 0: D:\\ORADB\\DV1\\REDO04A.LOG
Current log# 4 seq# 188 mem# 1: H:\\ORADB\\DV1\\REDO04B.LOG
Tue Sep 14 09:38:03 2021
Thread 1 advanced to log sequence 189 (LGWR switch)
Current log# 1 seq# 189 mem# 0: D:\\ORADB\\DV1\\REDO01A.LOG
Current log# 1 seq# 189 mem# 1: H:\\ORADB\\DV1\\REDO01B.LOG`;
// 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