import re
regex = re.compile(r"(?<!BM\.)(?<=\W)Draw(Image|Text)\s*([^\;\n]+)(\;|$)", flags=re.MULTILINE)
test_str = (" BM.DrawImage(GameOverImg,MW-ImageWidth(GameOverImg) , MH-ImageHeight(GameOverImg));\n"
" \n"
" gotxt=GetTextLine(60);\n"
" break;\n"
" \n"
" case 0: // если пориграли\n"
" BM.SetColor(255,0,0);\n"
" DrawImage GameOverImg,MW-ImageWidth(GameOverImg) , MH-ImageHeight(GameOverImg);\n\n"
" DrawText string gotxt,MW-TextWidth(gotxt)/2 , MH-TextHeight(gotxt)/2")
subst = "BM.Draw$1($2)$3"
result = regex.sub(subst, test_str)
if result:
print(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 Python, please visit: https://docs.python.org/3/library/re.html