$text = '$.ajax({type: "POST",url: "/dir1/dir2/ajax/ads",data: "view=list",dataType: "html",cache: false,success: function (data) {
}});';
$repl = 'ЗначениеДляЗамены';
$text = preg_replace('~url:\h"\K[^"]+(?=/ajax/ads)~', $repl, $text);
echo $text;