开发者

edit delimited string with regular expression

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.


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,


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜