You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
565 B

2 months ago
import re
# 读取txt文件
with open('我的全部弹幕.txt', 'r', encoding='utf-8') as file:
lines = file.readlines()
# 使用正则表达式提取包含“ai”或“AI”的弹幕去掉单词边界限制
ai_danmu = [line.strip() for line in lines if re.search(r'[Aa][Ii]', line)]
# 保存结果到新文件
with open('提取.txt', 'w', encoding='utf-8') as output_file:
for danmu in ai_danmu:
output_file.write(danmu + '\n')
# 输出提取的弹幕
print(f"提取了 {len(ai_danmu)} 条弹幕,其中包含 'ai''AI' 关键字。")