tags:

views:

38

answers:

2

I've a string like "Colors: yellow, green, white". I need to get an array ("yellow", "green", "white") from it and it needs to be done with one regex.

I'm trying to apply something like

var result = Regex.Match("Colors: green, white, yellow", @":(\s(?<result>.*?)(,|$))*");

what I get is that result.Groups["result"]=="yellow"

How can I get all the other colors? May be there's another way to do this?

A: 

Try result.Groups["result"].Captures

Idsa
exactly! thanks
Shaddix
+1  A: 

This snippet will get you an array of colours from your result Match object.

string[] colours = result.Groups["result"].Captures
    .Cast<Capture>()
    .Select(c => c.Value)
    .ToArray();
Daniel Chambers