Java - 如何将 irc 消息解析为人类可读的

标签 java irc

我正在用 Java 创建一个 irc 客户端。它工作正常,但来自服务器的消息有点“困惑” 例如 :User1!webirc@1.9.com PRIVMSG #channel :test。所以我想知道如何将 irc 消息解析为人类可读的?这是我为 irc 消息找到的 ^(:(\\S+) )?(\\S+)( (?!:)(.+?))?( :(.+))?$ 的正则表达式。

最佳答案

IRC 协议(protocol)记录如下:https://www.rfc-editor.org/rfc/rfc2812

2.3.1 Message format in Augmented BNF

The protocol messages must be extracted from the contiguous stream of octets. The current solution is to designate two characters, CR and LF, as message separators. Empty messages are silently ignored, which permits use of the sequence CR-LF between messages without extra problems.

The extracted message is parsed into the components , and list of parameters ().

The Augmented BNF representation for this is:

message    =  [ ":" prefix SPACE ] command [ params ] crlf
prefix     =  servername / ( nickname [ [ "!" user ] "@" host ] )
command    =  1*letter / 3digit
params     =  *14( SPACE middle ) [ SPACE ":" trailing ]
           =/ 14( SPACE middle ) [ SPACE [ ":" ] trailing ]

nospcrlfcl =  %x01-09 / %x0B-0C / %x0E-1F / %x21-39 / %x3B-FF
                ; any octet except NUL, CR, LF, " " and ":"
middle     =  nospcrlfcl *( ":" / nospcrlfcl )
trailing   =  *( ":" / " " / nospcrlfcl )

SPACE      =  %x20        ; space character
crlf       =  %x0D %x0A   ; "carriage return" "linefeed"

关于Java - 如何将 irc 消息解析为人类可读的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21016372/

相关文章:

python - 维基链接(irc 机器人)

c - 处理我的 IRC 机器人的身份

Python IRC 机器人不会加入

javascript - Chat Bot twitch IRC 集成,无法从 NAMES 421 Unknown Command 获得响应

java - 如何聚焦 JFrame?

java - jabba中的 'adopt'和 'adopt-openj9'有什么区别

java - Apache HttpClient 4.4 代理基本身份验证 : Multiple auth attemps

java - 从硬编码字符串数组切换到 getStringArray() 时崩溃

c# - 尝试中断卡在 reader.readLine() 中的线程

Java、克里奥 : Add fields to class persisted as FieldSerializer