s = "hello cats"
print(re.search(r"hello",s).groups())
Run Code Online (Sandbox Code Playgroud)
这打印().
根据文档,如果没有找到匹配项,groups()将返回一个空元组.那为什么不匹配呢?
groups返回匹配的组.你没有定义任何:
s = "hello cats"
print(re.search(r"(he)l(lo)",s).groups())
Run Code Online (Sandbox Code Playgroud)
版画 ('he', 'lo')