D
Dan
Hi. I'm new to regular expressions, and have what I hope is a basic
question.
In the file that my code is parsing, some lines may look like
:name:colour
:name:colour
and some lines may just have
:name
Note that the name and colour would actually be a name and a colour - not
the text "name" and "colour".
The regular expression below works for the case where there's both the name
and the colour, but not where there's just the name. How do I make it so
that the second parameter is optional?
Thanks for any info,
Dan.
Match m = Regex.Match (buffer, @"
?<name>.*)
?<colour>.*)");
name = m.Groups ["name"].ToString ();
colour_string = m.Groups ["colour"].ToString ();
question.
In the file that my code is parsing, some lines may look like
:name:colour
:name:colour
and some lines may just have
:name
Note that the name and colour would actually be a name and a colour - not
the text "name" and "colour".
The regular expression below works for the case where there's both the name
and the colour, but not where there's just the name. How do I make it so
that the second parameter is optional?
Thanks for any info,
Dan.
Match m = Regex.Match (buffer, @"


name = m.Groups ["name"].ToString ();
colour_string = m.Groups ["colour"].ToString ();