I have the following problem: I want to replace (in php) a special character, but only if it\'s between two other characters. It tried to find a solution with with preg_repl
A simple understandable solution could be the use of preg_replace_callback:
$str = preg_replace_callback('/"[^"]+"/', function ($m) { return str_replace(";", ":", $m[0]); }, $str);
"[^"]+" captures the quoted stuff to $m[0] where ; is replaced by :
"[^"]+"
$m[0]
;
:
See test at eval.in (link will expire soon)