const regex = new RegExp('^.*openat(?:[\\s\\S]*)^.*hammad.*', 'gm')
const str = `[pid 20242] 23:13:36 futex(0x7f8087eb18, FUTEX_WAKE, 1 <unfinished ...>
[pid 621] 23:13:36 futex(0x7f80855410, FUTEX_WAIT, 1041, NULL <unfinished ...>
[pid 20242] 23:13:36 <... futex resumed> ) = 0
[pid 621] 23:13:36 <... futex resumed> ) = -1 EAGAIN (Try again)
[pid 20242] 23:13:36 munmap(0x7f80200000, 8192 <unfinished ...>
--> [pid 621] 23:13:36 openat(AT_FDCWD, "/proc/self/task", O_RDONLY|O_DIRECTORY|O_CLOEXEC <unfinished ...>
[pid 20242] 23:13:36 <... munmap resumed> ) = 0
[pid 621] 23:13:36 <... openat resumed> ) = 13
[pid 20242] 23:13:36 madvise(0x7f76a7b000, 20480, MADV_DONTNEED <unfinished ...>
--> [pid 621] 23:13:36 hammad(13, FUTEX_WAKE, 1, 24 )
[pid 20242] 23:13:36 madvise(0x7f76a7b000, 20480, MADV_DONTNEED <unfinished ...>
[pid 621] 23:13:36 <... futex resumed> ) = 0
[pid 20242] 23:13:36 futex(0x7f80855410, FUTEX_WAKE, 1 <unfinished ...>
[pid 621] 23:13:36 futex(0x7f8087eb18, FUTEX_WAKE, 1 <unfinished ...>
[pid 20242] 23:13:36 <... futex resumed> ) = 0
[pid 621] 23:13:36 <... futex resumed> ) = 0
[pid 20242] 23:13:36 futex(0x7f8087eb18, FUTEX_WAKE, 1 <unfinished ...>
[pid 621] 23:13:36 futex(0x7f80855410, FUTEX_WAIT, 1041, NULL <unfinished ...>
[pid 20242] 23:13:36 <... futex resumed> ) = 0`;
// 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