25 lines
730 B
Python
25 lines
730 B
Python
import re
|
|
|
|
search = ["教学", "套路"]
|
|
|
|
rf = open("result.txt", "w", encoding="gbk")
|
|
|
|
with open("a.txt", "r", encoding="gbk") as f:
|
|
content = f.read(1 << 20)
|
|
result = re.findall(r"^(?P<title>[^\t\r\n]+)\t(?P<content>[^\t]+)\t(?P<aid>\d+)\t(?P<bvid>BV[^\t\r\n]+)$", content,
|
|
re.MULTILINE)
|
|
for item in result:
|
|
title, content, aid, bvid = item
|
|
matched = []
|
|
for line in content.split("\n"):
|
|
for key in search:
|
|
if key in line:
|
|
matched.append(line)
|
|
if len(matched) > 0:
|
|
rf.write("\n".join([
|
|
title,
|
|
*matched,
|
|
"",
|
|
"",
|
|
]))
|
|
rf.close() |