import re
regex = re.compile(r"^\t\t\t\tcompile: function\s*\([^)]+\)\s*\{\s*return\s+function\s*\(\s*([^)]+)\s*\)\s*\{\s*([^}]+?)\s*};\s+}")
test_str = (" compile: function(element, attrs, childTranscludeFn) {\n"
" return function ( scope, element, attrs, checkboxCtrl ) {\n"
" checkboxCtrl.init(scope.$parent.element);\n"
" };\n"
" }")
subst = "\\t\\t\\t\\tlink: function($1) {\\n\\t\\t\\t\\t\\t$2\\n\\t\\t\\t\\t}"
result = regex.sub(subst, test_str, count=1)
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