So I have this string: 'm(1,2),m(4,3)'
How can I split it to get list that contains only 2 elements: ['m(1,2)', 'm(4,3)']
I can't use str.split function because it will split the whole string and would give me something like this: ['m(1', '2)', 'm(4', '3)'] Can you help me?
CodePudding user response:
You can try regex:
import re
regex = re.compile("m\([0-9],[0-9]\)")
s = "m(1,2),m(4,3)"
regex.findall(s)
should yield:
['m(1,2)', 'm(4,3)']