# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<=\s)If\s+(.+);"
test_str = (" If ( x+w>0 And x-w<ScrW() ) And ( y+h>0 And y-h<ScrH() );\n"
" Return 1;\n"
" Else;\n"
" Return 0;\n"
" EndIf;\n\n"
" If Cur>Maximum Cur=0;\n\n"
" If Part.image<>Null;\n"
" If (dotX+x=>Part.x And dotX+x<Part.x+Part.w) And (doty+y=>Part.y And doty+y<Part.y+Part.h);\n"
" \n"
" // если над этим пикселем есть миддлграунд - то не меняем пиксель\n"
" If Not Part.IsMGpixel(x-Part.x+dotX,y-Part.y+doty);\n"
" \n"
" Local TPixmap TempPix= Part.Pixmap;\n"
" WritePixel( TempPix, x-Part.x+dotX ,y-Part.y+doty ,pixel);\n"
" Part.change=1;\n"
" \n"
" EndIf;\n"
" \n"
" Exit;\n"
" EndIf;\n"
" EndIf;")
subst = "if ($1)\\{"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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 Python, please visit: https://docs.python.org/3/library/re.html