import re
regex = re.compile(r"^\/(\*\*-+\*\*)\\$(.*?)^\\\1\/$|.", flags=re.DOTALL | re.MULTILINE)
test_str = ("/**--------------------------------------------------------------------------**\\\n"
"<summary>FunctionName</summary>\n"
"<returns>\n"
" Returns 1 on success.\n"
" Returns 0 on failure.\n"
"</returns>\n"
"<remarks>\n"
" This function is a function.\n"
"</remarks>\n"
"\\**--------------------------------------------------------------------------**/\n\n"
"int FunctionName()\n"
"{\n"
" int X = 1;\n"
" if(X == 1)\n"
" return 1;\n"
" return 0;\n"
"}")
subst = "$2"
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