const regex = /^(.*?)(?=On\s+\d{2}\-\d+\-\d+|\#{2}\-.*?\-\#{2})/s;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(.*?)(?=On\\s+\\d{2}\\-\\d+\\-\\d+|\\#{2}\\-.*?\\-\\#{2})', 's')
const str = `Second reply. #2
Met vriendelijke groet,
{sender name}
{company details}
On 25-02-15 14:38, {email name} wrote:
> [Ticket ID: 54e70396110971424425] Re: 54e70396110,678567.971424425
>
> ##- Please type your reply above this line -##
>
> Your request (54e70396110971424425) has been deemed solved. To reopen,
> please reply to this email or login on {name} to reply.
>
> ------------------------------------------------------------------------
>
> Feb 25, 14:38
>
> Dear Test user,
>
> First reply. #1
>
>
> {name}
> {company details}
>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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