const regex = /^(?=.*\bsubject\b)(?=.([\s\S]*)urgent)(?=.([\s\S]*)yahoo\.com).*$/gim;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?=.*\\bsubject\\b)(?=.([\\s\\S]*)urgent)(?=.([\\s\\S]*)yahoo\\.com).*$', 'gim')
const str = `User-Agent: Microsoft-MacOutlook/10.17.1.190326
Date: Wed, 05 Jun 2019 15:04:21 +0800
Subject: FW: DR OKE DANLDAI PLEASEURGENT
From: Dennis Chng <Dennischng@r-logic.com>
To: helpdesk <helpdesk@iqon-asia.com>,
Raynor Tan <raynor@iqon-asia.com>
Message-ID: <IQON.6059aba563.EF09158E-9BED-4A49-AE31-6851E971014F@r-logic.com>
Thread-Topic: DR OKE DANLDAI PLEASE URGENT
References: <341174902.187389.1559716703368.ref@mail.yahoo.com>
<341174902.187389.1559716703368@mail.yahoo.com>
In-Reply-To: <341174902.187389.1559716703368@mail.yahoo.com>
Mime-version: 1.0`;
// 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