<p>(.*?)test 365(.*?)<\/p>
<p>((?:(?!<\/p>).)*?\Ktest 365(?:(?!<\/p>).)*?)test 365(.*?)<\/p>
$1something else$2
<p>... test 365 ...</p>
<p>... test 365 ... test 365 ...</p>
<p>... test 365 ... test 365 ... test 365 ...</p>
<p>((?:.*?[^>])?)(test 365)(.*?)<\/p>
$1<a href="...">$2</a>$3