无法提取模式匹配的所有出现

时间:2019-04-12 15:54:32

标签: python regex search findall

我有一个文本,我想从中提取两个匹配字符串之间出现的文本。但是,当我尝试使用正则表达式而不是该范围的所有匹配项来提取它时,它将提取最后一个。

这是我尝试过的

string = "\n3.5\nFerguson to Gayle, FOUR, short of length delivery on the stump, 115.9km/h, Gayle clears that leg and clubs it off the toe-end just over mid-on to the long-on fence for four\n3.4\nFerguson to Gayle, no run, yorker length delivery, inch-perfect, 148.2km/h, digs it out off the toe-end\n3.3\nFerguson to Gayle, no run, slower delivery on a good length heading for middle, Gayle delays his defence from the crease back down the wicket\n3.3\nFerguson to Gayle, wide, 148.1km/h, wide down leg, swings away after the ball crosses the batsman's missed flick and swerves to the left of the 'keeper who has done well to collect it\n3.2\n"
re.findall("3.4(.*)3.3", string,  re.DOTALL)

我想要的是所有匹配项,即从\n3.4\nFergusonwicket\n3.3,而另一个\n3.4\nFergusontoe-end\n3.3,即都是匹配项。但是我的代码只给了我最大的代码。有什么办法吗?任何帮助将不胜感激。

注意:请理解,我想要的是所有可能的匹配模式,但是添加了吗?只给出第一个。

0 个答案:

没有答案
相关问题