$re = '/^(?=.*\bsubject\b)(?=.([\s\S]*)urgent)(?=.([\s\S]*)yahoo\.com).*$/im';
$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';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php