Mar-14-2020, 11:03 AM
You could have tried something yourself,maybe you have not started looked into regex as mention before
Here some quick test of something that may work or changed a little,depends on input text.
Here some quick test of something that may work or changed a little,depends on input text.
import re text = '''\ def my_game(): print('Game running') def 123 def foo(arg): pass def Bar(args*, kwargs**): pass hello def is nice def () wrong''' # Make list of match def_name = re.findall(r"def\s(\w+)\(.*", text) def_line = re.findall(r"def\s\w+\(.*", text) # Iterate over matches group() or group(1) matches = re.finditer(r"def\s(\w+)\(.*", text) for match in matches: print(match.group(1))
Output:my_game
foo
Bar
>>>
>>> def_name
['my_game', 'foo', 'Bar']
>>>
>>> def_line
['def my_game():', 'def foo(arg):', 'def Bar(args*, kwargs**):']
>>>