0
Follow
0
View

There is a text is QQ chat, as long as the text content, do not QQ network name and time record, how to do?

dunmas 注册会员
2023-02-27 08:32

The GPT answer is still pretty good. Adding re.S makes it even more accurate. Adding it also matches the newline before the z string, otherwise there would be a few more newlines.
The reference code is as follows, which is expected to be adopted.


z = re.sub(r'.*\d{2}:\d{2}:\d{2}\n', '', z, re.S)  # 替换为空字符串
print(z)
dyzwang4444 注册会员
2023-02-27 08:32

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > you can use regular expressions to match and replace the unnecessary information, for example, can match the format of the" QQ net time \ n ", replace it with an empty string, Keep only chat content:

import re

z = '''
QzAJ☀阿狼☀ 13:56:48
是谁逼走了兮兮!
QzAJ☀阿狼☀ 13:56:54
说!
QzAJ☀阿狼☀ 13:56:56
快说!????
QzAJ☀阿狼☀ 13:57:16
我下一句想说的是:“干得漂亮!”/斜眼笑
QzAJ☀阿狼☀ 13:57:28
大家好我来了/牛啊
/咖啡/咖啡/咖啡/咖啡/咖啡
'''

pattern = re.compile(r'.*\d{2}:\d{2}:\d{2}\n') # 匹配QQ网名和时间
z = re.sub(pattern, '', z) # 替换为空字符串
print(z)

Output:

是谁逼走了兮兮!
说!
快说!????
我下一句想说的是:“干得漂亮!”/斜眼笑
大家好我来了/牛啊
/咖啡/咖啡/咖啡/咖啡/咖啡


About the Author

Question Info

Publish Time
2023-02-27 08:32
Update Time
2023-02-27 08:32