# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?:(^(?:\s*)\/{4,}\n)+(^(\s*)\/{2,3}(?!\/)[\s\S]*\n)*\1)"
test_str = ("namespace sf {\n"
"////////////////////////////////////////////////////////////\n"
"/// \\ingroup system\n"
"/// \\brief Return a pointer to the Android native activity\n"
"/// \n"
"/// You shouldn't have to use this function, unless you want\n"
"/// to implement very specific details, that SFML doesn't\n"
"/// support, or to use a workaround for a known issue.\n"
"///\n"
"/// \\return Pointer to Android native activity structure\n"
"///\n"
"/// \\sfplatform{Android,SFML/System/NativeActivity.hpp}\n"
"///\n"
"////////////////////////////////////////////////////////////\n"
"SFML_SYSTEM_API ANativeActivity* getNativeActivity();\n\n"
" ////////////////////////////////////////////////////////////\n"
" // a \n"
" ////////////////////////////////////////////////////////////\n\n"
"} // namespace sf")
subst = "$3/**\\n$2$3 */\\n"
# 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