const regex = /(\-?\(.*\))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\-?\\(.*\\))', 'gm')
const str = `363
00:22:09,395 --> 00:22:11,996
Because he did only
meet me the once.
364
00:22:11,998 --> 00:22:13,597
Perhaps I could...
365
00:22:20,105 --> 00:22:21,772
(CLAMOURING)
366
00:22:21,774 --> 00:22:25,009
(INDISTINCT ANNOUNCEMENT
OVER PA)
367
00:22:55,340 --> 00:22:58,509
(INDISTINCT ANNOUNCEMENT
OVER PA)
368
00:23:10,655 --> 00:23:11,389
SARAH: Excuse me.
369
00:23:11,391 --> 00:23:14,225
Were there any men flying
alone on this fligh`;
// 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