I am trying to iterate each named group in a regular expression (i.e. - (?<name>.*)
) and depending on the name of the group set an instance property or add it to a collection. Important part is I will never know the name of the group when using the regular expression so I cannot use the string indexer on my Match. Is there a way to extract the names for my groups within my Match?
views:
37answers:
1
+4
A:
You can use Regex.GroupNameFromNumber
to iterate over all the capturing groups in the regex and find their names.
Anon.
2010-02-24 23:19:59
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.groupnamefromnumber.aspx
Alan Moore
2010-02-24 23:24:00
Perfect! Thank you!
Benny
2010-02-25 19:04:51