0

I am going to match something from a string, and I want to put all the matched strings into a list; how would I do that?

Right now I am using this

myStr = 'one two one three'
match = re.match(r'one', myStr)

But when I print the content of variable match using print m.group(), it only displays the first occurrence. I want to get all the occurrences and then put all those values into a list.

4

1 回答 1

2
>>> import re
>>> re.findall(r'one', 'one two one three')
['one', 'one']
于 2013-05-22T02:35:42.087 回答