Reputation: 2894
There are several questions regarding this topic, but none of them seem to answer this question specifically.
If I have the pattern p='([0-9]+)(,([0-9]+))*'
and s='1,2,3,4,5'
and I run m = re.match(p, s, 0)
I get a match (as expected). However, I would like to be able to print the list ('1', '2', '3', '4', '5')
. I can't seem to do this with the re.match
output. It gives me ('1', ',5', '5')
.
Also, how do I get the number of matches (in this case 5)?
Upvotes: 1
Views: 546
Reputation: 8910
Don't use regexes for that. s.split(',')
will do exactly what you want.
Upvotes: 5