tags:

views:

37

answers:

1

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?

+4  A: 

You can use Regex.GroupNameFromNumber to iterate over all the capturing groups in the regex and find their names.

Anon.
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.groupnamefromnumber.aspx
Alan Moore
Perfect! Thank you!
Benny