import re
fn_match = re.match(
    '(?P<function>\\w+)\\s?\\((?P<arg>(?P<args>\\w+(,\\s?)?)+)\\)', s)
fn_dict = fn_match.groupdict()
Regular expression to match function name and all arguments in Python