Regular exprssion for IRC messages
nohics at gmail.com
Fri Jul 17 12:59:47 EDT 2009
When an IRC client receive a messages, this message in in a special format
defined here: Message format in pseudo
For example we can have:
:MyNickName!n=MyUserName at 22.214.171.124 JOIN :#AnIrcChannel
:MyNickName!n=MyUserName at 126.96.36.199 PRIVMSG #AnIrcChannel :Hello here
:MyNickName!n=MyUserName at 188.8.131.52 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][^
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):
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list