$re = '/(.*)(Itemid=)(?!527)([1-9]*)/m';
$str = '/docman/?view=document&alias=690-uchwala-rady-miasta-nr-xv-100-2015-zmieniajaca-uchwale-nr-xxxiii-151-2012&category_slug=gminne-programy-i-strategie&Itemid=123
/docman/?view=document&alias=690-uchwala-rady-miasta-nr-xv-100-2015-zmieniajaca-uchwale-nr-xxxiii-151-2012&category_slug=gminne-programy-i-strategie&Itemid=494
/docman/?view=document&alias=690-uchwala-rady-miasta-nr-xv-100-2015-zmieniajaca-uchwale-nr-xxxiii-151-2012&category_slug=gminne-programy-i-strategie&Itemid=527';
$subst = "$1${2}494";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php