So I have this string and I want to parse it. Normally I would use string.split() for it but it's a bit complicated so I thought that may using regex is better in this case. But I am not too familar with regex. Maybe you girls/guys could help me out.
My string looks like this:
PING :sendak.freenode.net
Or like this
:[email protected] PRIVMSG #channelname :test
And should be parsed into it's components prefix, username, command, channel, text.
Example:
PING :sendak.freenode.net
Should be:
prefix=[] username=[] command=[PING] channel=[] text=[sendak.freenode.net]
and the string:
:[email protected] PRIVMSG #channelname :test
should be parsed to:
prefix=[[email protected]] username=[username] command=[PRIVMSG] channel=[#channelname] text=[test]
In the end I have to fill out these variables:
message.prefix = "";
message.username = "";
message.command = "";
message.channel = "";
message.text = "";
I am spliting a line at a time!
Fairly obvious that it's gonna be a small IRC chat.
The problem I expierence is that it can start with a ":" but does not have to.Thus making it fairly complex to realising using several splits().
Thanks for any help!
split()any more complicated than regex whensplit()takes a regex?