views:

133

answers:

2

hello everyone, i have a string which i want to edit a part of it. the string is like

"1:5,7:9,13:20,130:510,134:2,"

now all i want to do is remove the first part of those numbers like

"5,9,20,540,2,"

i tried a bunch of combinations but didn't get what i expected.

Regex rx = new Regex("[:]\\d+[,]");
    foreach (Match mx in rx.Matches("10:20,20:30,"))
    {
        Muhaha.InnerText += mx;
    }

it returns ":20,:30," but i want to capture only the number, nut the punctuation.

+2  A: 

How about using a Replace instead?

Regex r = new Regex("\\d+:");
string str = r.Replace("1:5,7:9,13:20,130:510,134:2,", "");
Console.WriteLine(str);

Prints:

5,9,20,510,2,
Aistina
it worked well, thanks. ( funny.. i am pretty sure i tried to replace it before. )
Batu
A: 

Try this, if you want to manipulate that numbers before joining them (if not, you should go with @Aistina answer):

foreach(Match m in Regex.Matches(
    "1:5,7:9,13:20,130:510,134:2,", 
    @":(?'number'\d+)"))
{
    Console.WriteLine(m.Groups["number"].Value);
}
Rubens Farias
aren't there any simple way to avoid capturing ":" and "," ?
Batu
`(?<=:)(?'number'\d+)(?=,)`
Rubens Farias