I have a problem building a working and correct pattern to re.finditer with multiple capturing groups in a pattern. I have the following string I want to search for data.
search_string="""
option.Map['2015'] = new CG.New.Option('text1', '2015', 100, 200);
option.Map['2016'] = new CG.New.Option('text2', '2016', 150, 210);
option.Map['2017'] = new CG.New.Option('text3', '2017', 160, 260);
"""
I would like to use Python regex to extract the text, the year, and the numbers. My pattern looks like the following:
pattern=r"option.Map\[\'(.*)\'] = new CG\.New\.Option\(\'(.*)\',\'(.*)\',(.*),(.*)\);"
My code looks like the following:
for finding in re.finditer(pattern,search_string):
print(finding.group(1))
print(finding.group(2))
print(finding.group(3))
print(finding.group(4))
print(finding.group(5))
I know that my pattern is off, but I don't know why.
The output I would expect/want to achieve looks like the following:
2015
text1
2015
100
200
2016
text2
2016
150
210
2017
text3
2017
160
260
unbalanced parenthesis at position 72give a hint?