fork download
  1. <?php
  2.  
  3. $re = '~\bcat\b(?![-:])~';
  4. $str = "my cat is hungry all the time\nthe products cat-1547 and cat:154 are disponible now";
  5. $subst = "Felix";
  6. $result = preg_replace($re, $subst, $str);
  7. echo $result;
Success #stdin #stdout 0.04s 52480KB
stdin
Standard input is empty
stdout
my Felix is hungry all the time
the products cat-1547 and cat:154 are disponible now