const regex = new RegExp('(\\d\\d-\\d\\d-\\d{4}.*?)(?=\\d\\d-\\d\\d-\\d{4}|$)', 'g')
const str = `05-01-2015 12:27 - KH - (KH) Igangværende - Opringning - 13-11 00:00 Fangede RLI på hans mobil. Ring igen kl. 15 19-11-2014 11:17 - KH - (KH) Igangværende - Opringning - 13-11 00:00 Gik på svarer igen og lagt besked til RLI at ringe tilbage. 12-11-2014 09:38 - KH - (KH) Igangværende - Opringning - 13-11 00:00 12-11-2014 09:32 - KH - (KH) Igangværende - Opringning - 15-10 00:00 Forsøgt RLI igen og lagt besked om han vil ringe. 14-10-2014 13:14 - KH - (KH) Igangværende - Opringning - 15-10 00:00 14-10-2014 13:10 - KH - (KH) Igangværende - Opringning - 14-10 00:00 Lagt besked til RLI at ringe 14-10-2014 13:06 - KH - (KH) Igangværende - Opringning - 14-10 00:00 test`;
// 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