所以,问题是,我正在收听游戏服务器的 telnet,我想捕捉玩家的消息。我正在收听的 telnet 消息的模板是这样的:
INF Chat: 'PLAYERNAME': THE PLAYER MESSAGE
但是我很快发现我的 re 表达式有问题,如果玩家名称包含:
':
它会将玩家的名字减半。
这是我到目前为止所做的:
example = "INF Chat: 'example player name': example message"
a = re.search("INF Chat: '(.*?)':", example)
print(a) # <_sre.SRE_Match object; span=(0, 32), match="INF Chat: 'example player name':">
但是当我尝试这个时,它会将玩家姓名减半:
example = "INF Chat: 'example ':player name': example message"
a = re.search("INF Chat: '(.*?)':", example)
print(a) # <_sre.SRE_Match object; span=(0, 21), match="INF Chat: 'example ':">
我希望第二个示例将玩家名称检测为“示例':玩家名称”,有人可以帮助我吗?谢谢。