From 8737e08f636c09d31667b87c167430ef26ebf3e2 Mon Sep 17 00:00:00 2001 From: palc3e6gq <1622356900@qq.com> Date: Tue, 17 Sep 2024 14:45:48 +0800 Subject: [PATCH] ADD file via upload --- 查找ai技术的弹幕.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 查找ai技术的弹幕.py diff --git a/查找ai技术的弹幕.py b/查找ai技术的弹幕.py new file mode 100644 index 0000000..7b22542 --- /dev/null +++ b/查找ai技术的弹幕.py @@ -0,0 +1,24 @@ +import re +# 指定要搜索的文件名 +filename = "总弹幕.txt" + +# 定义要搜索的关键字 +keywords = ["AI","ai","8K","8k","自动生成","定制化","3D","3d","全息视频","视障人士"] + +# 正则表达式模式,用于匹配包含所有关键字的行 +pattern = r'(?={})'.format('|'.join(keywords)) + +# 创建一个空列表来存放包含所有关键字的行 +relevant_lines = [] + +# 打开文件并逐行读取 +with open(filename, 'r',encoding='utf-8') as file: + for line_number, line in enumerate(file, 1): + # 如果行中包含所有关键字,将其添加到relevant_lines列表中 + if re.search(pattern, line, re.IGNORECASE): + relevant_lines.append(f"{line.strip()}") +# 打印结果 + +with open('AI弹幕.txt',mode='w',encoding='utf-8')as f: + for item in relevant_lines: + f.write(f"{item}\n")#写入text文件 \ No newline at end of file