Hello, When an IRC client receive a messages, this message in in a special format defined here: Message format in pseudo BNF<http://www.irchelp.org/irchelp/rfc/chapter2.html#c2_3_1>( http://www.irchelp.org/irchelp/rfc/chapter2.html#c2_3_1 ).
For example we can have: :mynickname!n=myusern...@41.238.129.121 JOIN :#AnIrcChannel :mynickname!n=myusern...@41.238.129.121 PRIVMSG #AnIrcChannel :Hello here :mynickname!n=myusern...@41.238.129.121 NICK :TheNewNickName :holmes.freenode.net 372 UnNickName :- a message here ... I want to transforme the message format defined in the irc protocole in the last link, to a regular expression to get the nickname, the username, the host, the commad, it's arguments if exist, and the message after ":" I'm programming in python and I have tried this regular expression: ^(:(\w+)(![^ \r\n]+)?(\...@[^ \r\n]+)? )?([a-zA-Z]+|\d\d\d)(( [^: \r\n][^ \r\n]*)+)( :[^\r\n]*)? Python code: nicknamePattern = re.compile(r'^(:(\w+)(![^ \r\n]+)?(\...@[^ \r\n]+)? )?([a-zA-Z]+|\d\d\d)(( [^: \r\n][^ \r\n]*)+)( :[^\r\n]*)?') matches = nicknamePattern.search(data) if matches != None: print matches.groups() But it doesn't seems to work all the time. So can you help me to make the correct regular expression please ? You can see some example of messages working or not with this pattren (when I try to connect to an irc server): http://www.developpez.net/forums/d779736/php/langage/regex/format-message-pseudo-bnf-expression-reguliere/#post4494010 Thanks.
-- http://mail.python.org/mailman/listinfo/python-list