Python:字符串匹配模式,可发现多次匹配

时间:2019-02-18 09:42:34

标签: regex python-3.x

我希望在我处理的所有字符串中都能找到一种模式。

regex = re.compile(r'<pc.*>')

string = "<pc  this is the 1st occurrence> words are displayed here <pc this is the second occurrence>"

re.findall(regex,string)

所需的输出:

['<pc this is first occurrence>', '<pc this is the second occurrence>']

实际输出:

["<pc  this is the 1st occurrence> words are displayed here <pc this is the second occurrence>"]

如何重新构造正则表达式以获得所需的输出

0 个答案:

没有答案