Re.findall显示tekst行

时间:2015-08-26 23:31:12

标签: python

我收到了以下代码:

import re

text = "He was carefully disguised but captured quickly by police."
print re.findall(r"\w+ly", text)

现在的输出是:

['carefully', 'quickly']

如何让我的re.findall这样,它会显示它找到的整行。就像有很多tekst,我正在用我的名字搜索所有内容。我怎样才能让它显示整行的tekst,而不仅仅是我的名字。

1 个答案:

答案 0 :(得分:1)

检查re.findall()是否返回任何内容,然后打印行:

text = "He was carefully disguised but captured quickly by police."
lines = [text, 't', 'l']
for line in lines:
    if re.findall(r"\w+ly", line):
        print line