Advertisement
Ethosa

Untitled

Nov 12th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. string = '''
  2. def testFunction(a, b):
  3.    print("hello world")
  4.  
  5. def _privateFunc(a):
  6.    pass
  7. def __protectedFunc(a):
  8.    pass
  9. '''
  10.  
  11. # string = re.sub(r"(?P<blockIndent>[ ]*)def[ ]*__(?P<functionName>[a-zA-Z0-9_])(?P<funcParams>[\s\S]+)[ ]*:[\r\n]+(?P<body>(?P<indent>[ ]+)[^\r\n]+[\r\n]+((?P=indent)[^\r\n]+[\r\n]+)*)",
  12. #         r'\g<blockIndent>protected void \g<functionName>\g<funcParams>{\n\g<body>\g<blockIndent>}\n', string)
  13. # string = re.sub(r"(?P<blockIndent>[ ]*)def[ ]*_(?P<functionName>[a-zA-Z0-9_])(?P<funcParams>[\s\S]+)[ ]*:[\r\n]+(?P<body>(?P<indent>[ ]+)[^\r\n]+[\r\n]+((?P=indent)[^\r\n]+[\r\n]+)*)",
  14. #         r'\g<blockIndent>private void \g<functionName>\g<funcParams>{\n\g<body>\g<blockIndent>}\n', string)
  15. string = re.sub(r"(?P<blockIndent>[ ]*)def[ ]*(?P<functionName>[a-zA-Z0-9_]+)\((?P<firstParam>[\s\S]+)(?P<other>[\s\S]+)\)[ ]*:",
  16.         r"\g<blockIndent>def \g<functionName>(Object \g<firstParam>, \g<other>):", string)
  17. string = re.sub(r"(?P<blockIndent>[ ]*)def[ ]*(?P<functionName>[a-zA-Z0-9_]+)\((?P<firstParam>(?<!Object)[^,][\s\S]+)(?P<other>[\s\S]+)\)[ ]*:",
  18.         r"\g<blockIndent>def \g<functionName>(Object \g<firstParam>, \g<other>):", string)
  19. # string = re.sub(r"(?P<blockIndent>[ ]*)def[ ]*(?P<functionName>[a-zA-Z0-9_])(?P<funcParams>[\s\S]+)[ ]*:[\r\n]+(?P<body>(?P<indent>[ ]+)[^\r\n]+[\r\n]+((?P=indent)[^\r\n]+[\r\n]+)*)",
  20. #         r'\g<blockIndent>public void \g<functionName>\g<funcParams>{\n\g<body>\g<blockIndent>}\n', string)
  21. print(string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement