【发布时间】:2020-08-11 04:07:09
【问题描述】:
我有一个聊天对话日志,我希望每个组的类型为 (Stranger|You): message。以下是聊天记录的格式:
foofoofoofoofoofooStranger: heyy You: asdasdasdassdasad Stranger: asdasdasd You: Stranger:asdasdasd You: bye You have disconnected.\n\n \n\n \n\x0c
我试过(Stranger:\s|You:\s)(.*?)(Stranger:\s|You:\s),但效果不太好。
【问题讨论】:
-
您可以将最后一部分更改为正向前瞻
(Stranger:\s|You:\s)(.*?)(?=Stranger:\s|You:\s)regex101.com/r/bnDFVT/1 或直到字符串末尾(Stranger:\s|You:\s)(.*?)(?=Stranger:\s|You:\s|$)regex101.com/r/cpD6kS/1