this my next question for regex. Honestly, i want to build animation for math multiply , when their input some formula, their will get animation to describe where is this number will counting, this part of my code.
$pattern = '([*])';
$replace = '||';
$stringAsli = (123*1.23*(0.12/8))*(123*512+40);
$replaceResult= str_replace($pattern,$replace,$stringAsli);
but i got result :
(123||1.23||(0.12/8))||(123||512+40)
i want result like this
(123||1.23||(0.12/8))*(123||512+40);
Extended Requirements
In this special case with quoted strings:
("123*1.23*n"*"(0.12/8)")*("123*512"+40)
should become
("123||1.23||n"$"(0.12/8)")*("123||512"+40)
In other words, still replace the *
inside the brackets, but if we're inside a quoted strings we replace with ||
, and if not we replace with $