I have a string like this.
$dot_prod = "at the coast will reach the Douglas County coast";
I'd like this result by using a regex: at the coast will reach the Douglas County coast
Specifically, I want to bold the word "coast" and "the" but only the word coast if not preceded by the word "county" and only the word "the" if not preceded by the word "at". So, essentially I want an array of words or phrases (case-insensitive that keeps the case the word/phrase was originally in) to be bolded and then an array of words or phrases that I want to ensure are not bolded. For instance, the array of words/phrases that I want bolded are:
$bold = array("coast", "the", "pass");
and the array of words I want to ensure are unbolded are:
$unbold = array("county coast", "at the", "grants pass");
I'm able to do the bolding with this:
$bold = array("coast", "the", "pass");
$dot_prod = preg_replace("/(" . implode("|", $bold) . ")/i", "<b>$1</b>", $dot_prod);
However, I've been unsuccessful at unbolding afterwards, and I definitely couldn't figure out how to do it all in one expression. Can you offer any help please? Thank you.