const regex = /((?:\d{2}:)?\d{2}:\d{2}\.\d{3})[^\n]+level[^\d]+(\d{3})/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((?:\\d{2}:)?\\d{2}:\\d{2}\\.\\d{3})[^\\n]+level[^\\d]+(\\d{3})', 'gm')
const str = `00:00.300 ID:4 zzzzzzzzzzz
00:02.155 ID:4 aaaaaaaaaaaaa
00:04.662 ID:4 dsadasd
**00:32.283** ID:4 level **790**
00:32.155 ID:4 Sfghgfs
00:32.200 ID:4 Tsdfsdfdfsff
**00:32.205** ID:4 level **640**
00:32.206 ID:4 Sadssd
00:32.208 ID:4 asdasgsfgsgsagsa
00:32.210 ID:4 adasgx
00:32.212 ID:4 Masddasdas.
**01:40:40.698** ID:4 level **500**`;
// 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