const regex = /(On\s.*<\n){0,1}(.*\n(\n){0,1}((^>+\s?.*$)+\n?)+)/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(On\\s.*<\\n){0,1}(.*\\n(\\n){0,1}((^>+\\s?.*$)+\\n?)+)', 'gmi')
const str = `test comment reply in email
On 10.05.2016 16:06, MRKTNG wrote:
> New Message
> MRKTNG <#>
>
> Your Profile Picture
>
> Lisa Radzishevsky <#>
> May 10, 2016, 8:06 am
>
>
>
>
>
> RE: Language learning
>
> test subject
>
>
> Reply
> <http://mandrillapp.com/track/click/30047086/vendori.local?p=eyJzIjoiLXVwS2lWRndOUXVibWozbmFVQ09qbVE3ZVdjIiwidiI6MSwicCI6IntcInVcIjozMDA0NzA4NixcInZcIjoxLFwidXJsXCI6XCJodHRwOlxcXC9cXFwvdmVuZG9yaS5sb2NhbFxcXC9kb2N1bWVudFxcXC80ODEwNCNkaXNjdXNzaW9uXCIsXCJpZFwiOlwiY2YwYWFhNWE1ZWY5NDZmMDhlNjJmNmRiMTAyZDY4Y2VcIixcInVybF9pZHNcIjpbXCJhYzE1OWI2NTM2YTM0ZDkzYmU1MzE5Y2VmN2IzOWEwZGQzMjY2NWRkXCJdfSJ9>
>
>
> © 2015 MRKTNG. All Rights Reserved.
> 1 W Superior St. • Chicago • IL 60654 USA <#>
>
`;
// 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