I'm trying to alter the content of an email generated by a plugin, removing a lengthy section that starts with <p> NOTE: (the space is actually a tab) and ending with /</a><br /> (lines 2-5 below). There are all sorts of characters and line feeds in between. I can't get the search to work. Here is the type of content and what I've tried at PHP Sandbox. I thought a non-greedy quantifier would work, but no joy.
$content = 'Weather: rainy</p>
<p> NOTE: You are entering the twilight zone:<br />
– No cell phones</p>
<p>Click here:<br />
<a href="https://www.example.com/" rel="nofollow">https://www.example.com/</a><br />
—<br />
To exit, visit:<br />
<a href="https://example.org/wp-admin/admin.php?page=twilight;subpage=global_options" rel="nofollow">https://example.org/wp-admin/admin.php?page=twilight;subpage=global_options</a><br />
To see current twilight zone conditions, visit:<br />';
$search = '~<p>\sNOTE[.\n\r]+?/</a><br />~';
$replace = '';
$content = preg_replace($search, $replace, $content);
echo $content;
preg_replaceisn't a WordPress function it's a PHP core function. I'd suggest asking on stackoverflow, but they might respond by saying you should use an XMLParser instead of regular expressions as Regex only works for very simply HTML and can't fully parse HTML due to its structure. Have you contacted the plugin author? There's probably a hook you can remove'~<p>\sNOTE(.|\s)+?/</a><br />~';, though I don't understand why the original didn't work.'~\tNOTE(.|\s)+?/</a><br />~'with nothing works as expected in PHP Sandbox, but it deletes the entire email content in Wordpress. Is it possible the email content when the filter is acting (mailtpl/email_contentfrom the Email Templates plugin) is different from the raw source content of the received email?