$re = '/(?<=\s)If\s+(.+);/m';
$str = ' If ( x+w>0 And x-w<ScrW() ) And ( y+h>0 And y-h<ScrH() );
Return 1;
Else;
Return 0;
EndIf;
If Cur>Maximum Cur=0;
If Part.image<>Null;
If (dotX+x=>Part.x And dotX+x<Part.x+Part.w) And (doty+y=>Part.y And doty+y<Part.y+Part.h);
// если над этим пикселем есть миддлграунд - то не меняем пиксель
If Not Part.IsMGpixel(x-Part.x+dotX,y-Part.y+doty);
Local TPixmap TempPix= Part.Pixmap;
WritePixel( TempPix, x-Part.x+dotX ,y-Part.y+doty ,pixel);
Part.change=1;
EndIf;
Exit;
EndIf;
EndIf;';
$subst = "if ($1)\{";
$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