我要匹配字符串中的内容,我想将所有匹配的字符串放入列表中;我该怎么做?
现在我正在使用这个
myStr = 'one two one three'
match = re.match(r'one', myStr)
但是当我使用match
打印变量print m.group()
的内容时,它只显示第一次出现。我希望得到所有出现的内容,然后将所有这些值放入列表中。
答案 0 :(得分:2)
>>> import re
>>> re.findall(r'one', 'one two one three')
['one', 'one']