preg_replace - I want to replace $p(x) = \\frac {x} {\\si$ to image

<?php
$string = ‘I want to replace this $p(x) = \frac {x} {\sigma^2} e^{\frac{{-x^2}}{2\sigma^2}}$ to image’;
$patterns = ‘/\$+[^a-zA-Z0-9]+[a-zA-Z0-9]\$/’;
echo “pattern”.$patterns.“<br>”;
$replacements = “<img src=‘err.png’/>”;
echo preg_replace($patterns, $replacements, $string);
?>

anybody is there to help me…

i want to replace the $p(x) = \frac {x} {\sigma^2} e^{\frac{{-x^2}}{2\sigma^2}}$ to image…

grt!.. Thankyou… It’s working…

This works for me:

$patterns = '/\\$[^\\$]*\\$/';

Finds a $, followed by any number of characters that aren’t a $, followed by a $.

So, anything between 2 $ signs, and the $s themselves, you want to replace?

ya i have to replace total string $ to $ including ‘$’ sign to image