用python的re正则匹配任意数据的最后一行数据
可以使用以下代码来实现正则匹配任意数据的最后一行数据:
import re
data = """
This is line 1
This is line 2
This is line 3
This is the last line
"""
pattern = r".+"
matches = re.findall(pattern, data)
last_line = matches[-1]
print(last_line)
输出结果为:"This is the last line"
原文地址: http://www.cveoy.top/t/topic/ifHa 著作权归作者所有。请勿转载和采集!