fork download
  1. <?php
  2.  
  3. $sym_rx = "~(?:([^-'\"()*,.:…;?`\s]+)|([-'\"()*,.:…;?`]))(\s)*~u";
  4. $str = "'this' is Mary! (a dog - not a human)";
  5. echo preg_replace_callback($sym_rx, function ($m) {
  6. $ins = !empty($m[2]) ? $m[2] . "\\SYM" : $m[1] . "\\not SYM";
  7. return !empty($m[3]) ? $ins . $m[3] : $ins . " ";
  8. }, $str);
  9.  
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
'\SYM this\not SYM '\SYM is\not SYM Mary!\not SYM (\SYM a\not SYM dog\not SYM -\SYM not\not SYM a\not SYM human\not SYM )\SYM