How can I capture class and methods from a python file?
I don't care about the attrs or args.
class MyClass_1(...):
...
def method1_of_first_class(self):
...
def method2_of_first_class(self):
...
def method3_of_first_class(self):
...
class MyClass_2(...):
...
def method1_of_second_class(self):
...
def method2_of_second_class(self):
...
def method3_of_second_class(self):
...
What I tried so far:
class ([\w_]+?)\(.*?\):.*?(?:def ([\w_]+?)\(self.*?\):.*?)+?
Options: dot matches newline
CAPTURING THE CLASS
Match the characters “class ” literally «class »
Match the regular expression below and capture its match into backreference number 1 «([\w_]+?)»
Match a single character present in the list below «[\w_]+?»
Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?»
A word character (letters, digits, etc.) «\w»
The character “_” «_»
Match the character “(” literally «\(»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “)” literally «\)»
Match the character “:” literally «:»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
CAPTURING THE METHODS:
Match the regular expression below «(?:def ([\w_]+?)\(self.*?\):.*?)+?»
Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?»
Match the characters “def ” literally «def »
Match the regular expression below and capture its match into backreference number 2 «([\w_]+?)»
Match a single character present in the list below «[\w_]+?»
Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?»
A word character (letters, digits, etc.) «\w»
The character “_” «_»
Match the character “(” literally «\(»
Match the characters “self” literally «self»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “)” literally «\)»
Match the character “:” literally «:»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
But it only captures the class name and the first method, I think that's because the backreference number 2 can't capture more than 1, even tho it's inside a (?:myregex)+?
Current Output:
'MyClass_1':'method1_of_first_class',
'MyClass_2':'method1_of_second_class'
Desired Output:
'MyClass_1':['method1_of_first_class','method2_of_first_class',...],
'MyClass_2':['method1_of_second_class','method2_of_second_class',...]