I need assistance creating my Regex String, to parse CHAT, the format TALK is recieved is:
1007 TALK USERNAME 1002 "The Message Here "See""
The text is encased in "'s and I can't split it anyway, without losing portions of the message.
This is my current Regex String, that correctly parses all other CHAT sent to it, except TALK:
Regex rex = new Regex("(?<flags>\\d{4}) (?<opcode>TALK|INFO|ERROR|CHANNEL) \"(?<text>[^\\n]*)\"", RegexOptions.IgnoreCase);
I believe I need something along the lines of:
Regex rex = new Regex("(?<flags>\\d{4}) (?<opcode>TALK|INFO|ERROR|CHANNEL) (?<username>*) (?<somecode>\\d{4} \"(?<text>[^\\n]*)\"", RegexOptions.IgnoreCase);
However, that string does not work....can anyone help?
When using the @ character to make a string literal, you can escape a quotation mark with another quotation mark:
@"('|"")"
Don't know if that helps, I got the idea from VB, how you can do """" for a quotation mark.
No, sorry. That doesn't really apply to this at all.
Why do you want to parse the CHAT protocol? It's dead...
Warnet ;)
Yep, warnet ;). I'm making a Chat/Warbot for warnet in C#, as .NET Sockets are sexyfast. Can anyone post some useful information ... ?
Which part of the Regex is breaking? I'm guessing the <text> part? Can you post just the text part, and what each bit of it does? I'm not familiar with the C#-style syntax, it's different than what I'm used to.
I'd just get greedy:
\"(?<Message>.*)\"
Should grab everything between the first and last quote.
Just tried that, doesn't work, only takes what's in the first found quote to the NEXT found quote, messages containing quotes fuck up.
Use \x22 :D
Btw you should read msdn before asking on forums :o
http://msdn2.microsoft.com/en-us/library/4edbef7e(VS.71).aspx
Quote from: Smarter on June 18, 2007, 04:10 AM
Just tried that, doesn't work, only takes what's in the first found quote to the NEXT found quote, messages containing quotes fuck up.
You must be doing something wrong, because it works for me.
In Rad Regular Expression Designer, I used these values:
Input - "I am quoting someone, "a penny saved is a penny earned". Eric says, "This works!""
RegEx - "(?<Message>.*)"
I tried that, and it returned:
[12:01 AM] <.eVe.HaZe> 1005 TALK .eVe.HaZe 0010 "~.eVe.~ - QaYiN Chat v1.1.2"
case "1005": //TALK
main.AddChat("<" + stSplt[2] + "> " + GetTalk(data), Color.White);
break;
My Talk Parse.
public string GetTalk(string str)
{
Regex rex = new Regex("(?<text>.*)", RegexOptions.IgnoreCase);
Match m = rex.Match(str);
string messageText;
if (m.Success)
{
return messageText = m.Groups["text"].Value;
}
else
{
return str;
}
}
My GetTalk function, as you can see, it's still not parsing it correctly....
Well, you need to include the quotes...
Regex rex = new Regex("\"(?<text>.*)\"", RegexOptions.IgnoreCase);
I think that should work.
If you fail to get the regex working, another simple way is to go right to the first quote and left to the second.
Wow, I really need to stop smoking pot, I completely forgot to include the beginning quotes.... it work's perfectly now, thanks.
Good to hear, since you started this thread almost a month ago.
Quote from: Chriso on July 05, 2007, 03:43 AM
Good to hear, since you started this thread almost a month ago.
Yeah, I poked into the source today and reviewed everyones posts, and realized how simple of an error it is... that's the problem with alot of my programs, I always seem to miss the simple things. On another note, what is going on with MirageBot, Chriso?
It should be coming out in a week or two.
I was told you lost the source and all kinds of junk like that?
Quote from: Smarter on July 05, 2007, 02:18 AM
Wow, I really need to stop smoking pot, I completely forgot to include the beginning quotes.... it work's perfectly now, thanks.
No problem.