const regex = /(?:\b(?:your|amazon\.com|shipped)\b.*){3}/ig;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:\\b(?:your|amazon\\.com|shipped)\\b.*){3}', 'ig')
const str = `Your Amazon.com order has shipped (#114-7286434-0549003)
Fwd: Your Amazon.com order of "Diva Ring Light Nebula 18..." has shipped!
Your Amazon.com order has shipped (#114-7286434-0549003)
Your Amazon.com order has shipped
Fwd: Your sdjcns order has deleted
Fwd: Your amazon order is cancelled
Your Amazon.in order (#171-8110001-7994703) of "Prestige Electric Kettle..." has been dispatched!
Your Amazon.in order #171-8110001-7994703 has been delivered
Your Amazon.in order #171-8110001-7994703 is out for delivery
Your Amazon.in order #171-8110001-7994703 has been shipped
Fwd: Your Amazon.com order of "Diva Ring Light Nebula 18..." has shipped!`;
// 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