0
s = "hello cats"
print(re.search(r"hello",s).groups())

这打印()

根据文档,如果未找到匹配项,则 groups() 返回一个空元组。那么为什么不匹配呢?

4

1 回答 1

6

groups返回匹配的。您没有定义任何:

s = "hello cats"
print(re.search(r"(he)l(lo)",s).groups())

印刷('he', 'lo')

于 2012-12-13T07:51:29.353 回答