I am trying to separate all the functions within square brackets and store them in a dictionary. However, the output strips the closing bracket from all the outputs except the last one.
import re
line="[f(x,y),g(y,z),f1(x1,y1)]"
matches = re.match(r"(.*)(\[)(.*)(\])(.*)", line)
if matches:
all_action_labels = matches.group(3)
sep_action_labels = re.split(r'\),',all_action_labels)
j=0
for x in sep_action_labels:
print(f'Function #{j+1} : {x}')
All the outputs, as you can see, are missing the closing bracket')' except last one :
Function #1 : f(x,y
Function #1 : g(y,z
Function #1 : f1(x1,y1)
What regular expression should I use?
Further, how can I store these output in a dictionary?