fork(2) download
  1. <?php
  2.  
  3. $wordToMatch = "-abc";
  4. $re = "/(?<!\\w)" . $wordToMatch . "(?!\\w)/";
  5. $str = "abc-abc -abc";
  6. $subst = "!$0!";
  7. $result = preg_replace($re, $subst, $str);
  8. echo $result;
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
abc-abc !-abc!