import re
regex = re.compile(r"Print\h+(#\w+)", flags=re.MULTILINE)
test_str = ("Print #FileNo, Tab(1); \"My Text Here\";\n"
"Print #FileNo, Tab(col); Txt;\n"
"Print #FileNo, Tab(100); Format(TheDate, \"DDMMMYYYY\") & \" \" & Variable_Name & \"Field : \" & Format(Field, \"x\")\n"
"Print #FileNo, Tab(1); Format(TheDate, \"x\") & \" - \" & TheName;\n"
"Print #FileNo, String(132, \"-\")\n"
"Print #FileNo, Tab(6); \"SOME VALUE\"; \"SOME MORE VALUES\";\n\n"
"Print #FileNo, Tab(100); \"First Text\"; \"Second Text\"\n"
"Print #FileNo, \"Third Text\"; \"Fourth Text\"\n")
subst = "MyPrint \\1"
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