例如,我有类似的东西:
OLD
WHO IS THIS
END?
On Sun, 22 Sep 2019 at 23:57,
我想从一开始就捕捉到一切{@ {1}}
所以我的预期结果是:
\n\nOn Sun,
我尝试执行以下模式:OLD
WHO IS THIS
END?
仅在我需要的文本不包含新行时才有效。我真的很感谢您的帮助。谢谢。
答案 0 :(得分:2)
无需Regex,请尝试以下操作:
text = """
OLD
WHO IS THIS
END?
On Sun, 22 Sep 2019 at 23:57,
"""
text = '\n'.join(line for line in text.split('\n') if line.startswith('On Sun'))
print(text)
输出:
OLD
WHO IS THIS
END?
答案 1 :(得分:0)