<div dir="ltr"><p>Hello,</p><p>When an IRC client receive a messages, this message in in a special format defined here: <a href="http://www.irchelp.org/irchelp/rfc/chapter2.html#c2_3_1" title="Message format in pseudo BNF">Message format in pseudo BNF</a> ( <a href="http://www.irchelp.org/irchelp/rfc/chapter2.html#c2_3_1">http://www.irchelp.org/irchelp/rfc/chapter2.html#c2_3_1</a> ).</p>
<p>For example we can have:</p><p>
:MyNickName!n=<a href="mailto:MyUserName@41.238.129.121">MyUserName@41.238.129.121</a> JOIN :#AnIrcChannel<br>
:MyNickName!n=<a href="mailto:MyUserName@41.238.129.121">MyUserName@41.238.129.121</a> PRIVMSG #AnIrcChannel :Hello here<br>
:MyNickName!n=<a href="mailto:MyUserName@41.238.129.121">MyUserName@41.238.129.121</a> NICK :TheNewNickName<br>
:<a href="http://holmes.freenode.net">holmes.freenode.net</a> 372 UnNickName :- a message here ...</p><p>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 ":"</p><p>I'm programming in python and I have tried this regular expression:</p><p>
^(:(\w+)(![^ \r\n]+)?(\@[^ \r\n]+)? )?([a-zA-Z]+|\d\d\d)(( [^: \r\n][^ \r\n]*)+)( :[^\r\n]*)?</p><p>Python code:</p><p>nicknamePattern = re.compile(r'^(:(\w+)(![^ \r\n]+)?(\@[^ \r\n]+)? )?([a-zA-Z]+|\d\d\d)(( [^: \r\n][^ \r\n]*)+)( :[^\r\n]*)?')<br>
matches = nicknamePattern.search(data)<br>if matches != None:  print matches.groups()<br></p><p>But it doesn't seems to work all the time. So can you help me to make the correct regular expression please ?</p><p>You can see some example of messages working or not with this pattren (when I try to connect to an irc server): <a href="http://www.developpez.net/forums/d779736/php/langage/regex/format-message-pseudo-bnf-expression-reguliere/#post4494010">http://www.developpez.net/forums/d779736/php/langage/regex/format-message-pseudo-bnf-expression-reguliere/#post4494010</a><br>
</p>Thanks. <p><br></p></div>