const regex = new RegExp('(?=\\[\\d\\d.\\d\\d.\\d\\d, \\d\\d:\\d\\d\\])', 'mg')
const str = `[29.01.18, 23:33] Alice: Ist das hier ein Chatverlauf?\\n[29.01.18, 23:45] Bob: Ja ist es!\\n[29.01.18, 23:45] Bob: Der ist dazu da die funktionsweise des Parsers zu demonstrieren\\n[29.01.18, 23:46] Alice: PTT-20180129-WA0025.opus (Datei angehängt)\\n[29.01.18, 23:46] Bob: Ah, er kann also auch erkennen ob Voicemails gesendet wurden!\\n[29.01.18, 23:46] Bob: Das ist praktisch!\\n[29.01.18, 23:47] Bob: Oder?\\n[29.01.18, 23:47] Alice: ja😄\\n[29.01.18, 23:47] Alice: und Emojis gehen auch!\\n[29.01.18, 23:47] Bob: Was ist mit normalen Smilies?\\n[29.01.18, 23:49] Alice: Keine Ahnung, lass uns das doch mal ausprobieren\\n[29.01.18, 23:50] Bob: Alles klar :) :D\\n[29.01.18, 23:51] Alice: Scheint zu funktionieren!:P\\n[29.01.18, 23:51] Bob: Meinst du, dass URLS auch erkannt werden?\\n[29.01.18, 23:52] Bob: Schick doch mal eine zum ausprobieren!\\n[29.01.18, 23:53] Alice: https://github.com/JuKo007\\n[29.01.18, 23:58] Alice: Scheint zu funktionieren!\\n[29.01.18, 23:59] Alice: Sehr schön!\\n[30.01.18, 00:00] Alice: Damit sollten sich WhatsApp Verläufe besser quantifizieren lassen!\\n[30.01.18, 00:02] Bob: Alles klar, los gehts 😌\\n`;
// 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