if re.findall(r"i am .*", a):
reg = re.compile(r" i am ([\w]+).*?$")
print('How long have you been {}?'.format(*reg.findall(a)))
所以如果我输入:
i am struggling with life...
它应该输出:
How long have you been struggling?
但由于某种原因,我得到一个元组错误?
顺便说一句,a 只是一个输入字段。
Traceback (most recent call last):
File "program.py", line 14, in <module>
print('How long have you been {}?'.format(*reg.findall(a)))
IndexError: tuple index out of range