fork(4) download
  1. <?php
  2. $mystring = "(123*1.23*(0.12/8))*(123*512+40)";
  3. $regex="~\((?:[^()]++|(?R))*\)~";
  4. $replaced = preg_replace_callback($regex,
  5. function($m) { return str_replace("*","||",$m[0]);},
  6. $mystring);
  7. echo $replaced;
  8.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
(123||1.23||(0.12/8))*(123||512+40)