const regex = /^\d+$\n/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\d+$\\n', 'gm')
const str = `278
00:15:13,442 --> 00:15:14,436
Mr. Burns,
279
00:15:14,454 --> 00:15:17,893
I came here because my brother
is about to be wrongfully convicted,
280
00:15:17,947 --> 00:15:19,514
and the man I'm looking for
281
00:15:19,542 --> 00:15:21,010
would help me find the truth.
282
00:15:21,038 --> 00:15:21,907
Don't you get it?
283
00:15:21,932 --> 00:15:23,918
I don't care who you are
or what you want.
284
00:15:25,167 --> 00:15:26,801
Now get lost.
285
00:15:29,102 --> 00:15:31,170
I think you just sent away
the first person
`;
// 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