const regex = /^(\d{2}:\d{2}:\d{2}[.,]\d{3})\s-->\s(\d{2}:\d{2}:\d{2}[.,]\d{3})\n(.*(?:\r?\n(?!\r?\n).*)*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\d{2}:\\d{2}:\\d{2}[.,]\\d{3})\\s-->\\s(\\d{2}:\\d{2}:\\d{2}[.,]\\d{3})\\n(.*(?:\\r?\\n(?!\\r?\\n).*)*)', 'gm')
const str = `WEBVTT
1
00:00:00.310 --> 00:00:02.540
Dans cette séquence, nous
allons voir pourquoi nos
2
00:00:02.550 --> 00:00:05.210
assistants personnels,
smartphones et tablettes, sont
3
00:00:05.210 --> 00:00:07.420
devenus tout
naturellement, en une dizaine d'années
4
00:00:07.420 --> 00:00:10.100
seulement, un point de collecte
majeur de données personnelles.
5
00:00:10.520 --> 00:00:13.140
Pourquoi le smartphone
intéresse-t-il tant de monde ?
6
00:00:15.690 --> 00:00:17.550
Tout d'abord, il faut
être conscient que dans un
7
00:00:17.550 --> 00:00:20.110
smartphone, 2 niveaux
existent. Il y a la partie visible
8
00:00:20.150 --> 00:00:23.440
avec son processeur dont on
va vanter les performances,
9
00:00:23.440 --> 00:00:26.260
le système d'exploitation
- dans ce module, nous nous`;
// 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