The preg_replace function in PHP provides a limit parameter. For instance, the first occurrence of medium replace with original, and the second occurrence of medium replace with "type".
$path = "demo\/medium\/Web081112_P001_medium.jpg";
$path = preg_replace ("/medium/","original",$path,1);
$path = preg_replace ("/medium/","type",$path,2);
echo $path;
// output : demo\/original\/Web081112_P001_type.jpg
So, are there any way using JQuery/ JavaScript to implement similar function? Thanks