Reputation: 16691
I have the following that I need to place into match groups.
a = '1,2,3(1)'
b = '1,2,3'
parsing a is fine,
>>> m = re.match('^([0-9,-,\,]*)(\([0-9]*\))',a)
>>> m.groups()
('1,2,3', '(1)')
I just need to confirm how to make the second match group optional so I can parse the variable b.
Upvotes: 4
Views: 1770
Reputation: 67968
m = re.match('^([0-9,-,\,]*)(\([0-9]*\))?',a)
^^
This should do it for you
Upvotes: 7