# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(^[ \t]*)Global([^\n\;\/]*);?"
test_str = ("Global Base:TList=New TList; // База загруженных спрайтив. Чтобы не грузить одно и то же\n\n"
"//цвета ключевых пикселей, испульзуемых в поиске\n"
"Global PxAlpha = -GenRgb(0, 0, 0, 0) \n"
"Global PxRed = -GenRgb(0, 1, 0, 0) // 65536\n"
"Global PxBlack = -GenRgb(1, 0, 0, 0); // 16777216 \n\n"
"Global => public static")
subst = "$1public static$2;"
# 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