tags:

views:

47

answers:

1

This is my second attempt to get this answer since I messed it up first time :s As you can guess Im new to regex

basically, the string contains lots of words seperated by "\"'s. so for example

\gyifgy8i\gyigyi9g\player_0\k1ng*tar%\gp86gg78.\g79g\player_1\th3dadY>\gyigyigiy\huiohgiu\player_2\j0k$r\g68g6o9g\987pgh890\player_3\PLAYERNAME

I need a patter which can match each word after \player_n\ , where n is a number. so from the above i want to match k1ng*tar% and th3dadY> and j0k$r (without the \ either side). these are player names from a UDP query, the udp query sperates every value with "\". every player name is always preceeded by \player_n\ as you can see above.

originally i was advised to used:

string rex = @"[\w]*[\\]player_[0-9]+[\\](?<name>[A-Za-z0-9]*)\b";
        Regex re = new Regex(rex);


            for (Match m = re.Match(stringData); m.Success; m = m.NextMatch())
        {

            players[count] = (m.Groups["name"]).ToString();
            textBox1.Text += players[count] + "\r\n";
            MessageBox.Show((m.Groups["name"]).ToString());
        }

The above pattern kinda works, but only if the playername is using A-Za-z0-9. I didnt realise at the time that playername can contain any character. can someone modify this pattern for me please, regex is beyond me :<

Thanks in advance.

+3  A: 

Provided the rest of the regex works as desired, you could replace

(?<name>[A-Za-z0-9]*)

with

(?<name>[^\\]*)

which will match everything except \

Garrett
this was better, but still not 100%, i did get a better result however i just ran the app now, the udp string had a few obscure playernames, for example: VM_C)-(r!s.cl and: dezerTer//cl. neither of these names were matched by your new regex :< Any more ideas?
brux
sry, this does actually work...its got smt to do with the return string from udp, for some reason udpclient us not recieing the full string :s
brux