var val='http://site.org/images/photos/small/tmp.jpg'; val=val.replace(/small/,'medium'); alert(val); val=val.replace(/\/smal|medium\//,''); alert(val);