代码
import re
string1 = """The Euro STOXX 600 index, which tracks all stock markets across Europe including the F
TSE, fell by 11.48% – the worst day since it launched in 1998. The panic 1334 selling prompted by the coronavirus has wiped £2.7tn off the value of STOXX 600 shares since its all-time peak on
19 February."""
s8=re.search(r".+\s(.+ex).+\s(\d\d\s.+).",string1)
s8.groups()
print(s8)
预计将打印(“索引”,“2月19日”)
错误
s8.groups()
^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'groups'
有谁能告诉我为什么会出现这个错误吗?
1条答案
按热度按时间ergxz8rk1#
默认情况下,
.
不匹配行尾,因此在输入字符串中找不到匹配项,s8
最终为空。您可以通过传递
re.DOTALL
标志来更改该行为: