I am trying to extract the string before a parenthesis using regex positive lookbehind like so, but it returns a none type. I want any string before a "(" , so I did this:
func = "public long int void myfunc(int int1, int int2);"`
pattern = "(?<=\()[a-zA-z0-9] \s?"
temp = re.match(pattern, func)
how can I return the string "myfunc" ?
CodePudding user response:
I should have been using regex look ahead:
pattern = "[a-zA-z0-9] \s?(?=()" this did the trick
CodePudding user response:
Maybe this:
([a-zA-Z_][a-zA-Z_0-9]*)(?=\s*\()
, because the function names in many languages start with letters and underscores, then maybe more than one of them or a digit follows. Then is the look ahead possible spaces and the required opening parenthesis.