I am trying to split a C program by its function blocks. For example,
I tried using regex library and try to split by (){
. But of no use. Not sure where to begin.
string = """
int firt(){
if () {
}
}
customtype second(){
if () {
}
for(){
}
}
fdfndfndfnlkfe
"""
And I want the result to be a list that has each of the function block as an element: ['int first(){ ... }', 'customtype second(){....}']
I tried the following but getting None
import regex
import re
reg = r"""^[^()\n]+\([^()]*\)\s*
\{
(?:[^{}]*|(?R))+
\}"""
print(regex.match(reg, string))