Valhalla Legends Forums Archive | Battle.net Bot Development | [C#] Regex String Troubles...

AuthorMessageTime
Smarter
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?
June 12, 2007, 11:03 AM
DDA-TriCk-E
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.
June 12, 2007, 11:38 AM
Smarter
No, sorry. That doesn't really apply to this at all.
June 12, 2007, 12:08 PM
rabbit
Why do you want to parse the CHAT protocol?  It's dead...
June 12, 2007, 12:40 PM
DDA-TriCk-E
Warnet  ;)
June 12, 2007, 1:02 PM
Smarter
Yep, warnet ;). I'm making a Chat/Warbot for warnet in C#, as .NET Sockets are sexyfast. Can anyone post some useful information ... ?
June 12, 2007, 1:15 PM
iago
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.
June 12, 2007, 2:53 PM
Insolence
I'd just get greedy:
[code]\"(?<Message>.*)\"[/code]

Should grab everything between the first and last quote.
June 18, 2007, 8:01 AM
Smarter
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.
June 18, 2007, 9:10 AM
DDA-TriCk-E
Use \x22  :D

Btw you should read msdn before asking on forums :o
http://msdn2.microsoft.com/en-us/library/4edbef7e(VS.71).aspx
June 18, 2007, 1:27 PM
Insolence
[quote author=Smarter link=topic=16779.msg170223#msg170223 date=1182157810]
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.
[/quote]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>.*)"
June 20, 2007, 1:09 AM
Smarter
I tried that, and it returned:

[12:01 AM] <.eVe.HaZe> 1005 TALK .eVe.HaZe 0010 "~.eVe.~ - QaYiN Chat v1.1.2"

[code]                case "1005": //TALK
                    main.AddChat("<" + stSplt[2] + "> " + GetTalk(data), Color.White);
                    break;[/code]
My Talk Parse.

[code]
        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;
            }
        }
[/code]

My GetTalk function, as you can see, it's still not parsing it correctly....
June 20, 2007, 4:03 AM
Insolence
Well, you need to include the quotes...
[code]Regex rex = new Regex("\"(?<text>.*)\"", RegexOptions.IgnoreCase);[/code]

I think that should work.
June 21, 2007, 7:18 AM
rabbit
If you fail to get the regex working, another simple way is to go right to the first quote and left to the second.
June 21, 2007, 1:29 PM
Smarter
Wow, I really need to stop smoking pot, I completely forgot to include the beginning quotes.... it work's perfectly now, thanks.
July 5, 2007, 7:18 AM
DDA-TriCk-E
Good to hear, since you started this thread almost a month ago.
July 5, 2007, 8:43 AM
Smarter
[quote author=Chriso link=topic=16779.msg170734#msg170734 date=1183625011]
Good to hear, since you started this thread almost a month ago.
[/quote]

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?
July 5, 2007, 9:01 AM
DDA-TriCk-E
It should be coming out in a week or two.
July 5, 2007, 10:25 AM
Smarter
I was told you lost the source and all kinds of junk like that?
July 5, 2007, 10:45 AM
Insolence
[quote author=Smarter link=topic=16779.msg170733#msg170733 date=1183619935]
Wow, I really need to stop smoking pot, I completely forgot to include the beginning quotes.... it work's perfectly now, thanks.
[/quote]No problem.
July 5, 2007, 10:52 AM

Search