fork download
  1. <?php
  2.  
  3. $dot_prod = "at the coast will reach the Douglas County coast";
  4. $bold = array("coast", "the", "pass");
  5. $unbold = array("county coast", "at the", "grants pass");
  6. usort($unbold, function($a, $b) { return strlen($b) - strlen($a); });
  7. usort($bold, function($a, $b) { return strlen($b) - strlen($a); });
  8. $rx = "~\b(?:" . implode("|", $unbold) . ")\b(*SKIP)(*F)|\b(?:" . implode("|", $bold) . ")\b~i";
  9. echo "$rx\n";
  10. echo preg_replace($rx, "<b>$0</b>", $dot_prod);
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
~\b(?:county coast|grants pass|at the)\b(*SKIP)(*F)|\b(?:coast|pass|the)\b~i
at the <b>coast</b> will reach <b>the</b> Douglas County coast