Enumerate Groups NAMES in System.Text.RegularExpression (.NET 1.1, VS2003)

  • Thread starter Thread starter Mike Jansen
  • Start date Start date
M

Mike Jansen

In .NET Framework 1.1 Visual Studio .NET 2003, System.Text.RegularExpression
namespace, I'm attempting to enumerate the Group Names from a Match.Groups.
For example:

Regex ex = new Regex("blah blah (?<group1>blah blah)");
Match match = ex.Match("input");
if (match.Success)
{
foreach (string groupName in match.Groups.??EnumeratorForGroupNames??)
{
// process the group
}
}

I need the group name because I want to move all groups into a Hashtable to
be passed to the generic handler. I don't want to maintain the regular
expression and a list of groups. I will if I have to but thought the info
should already be present in the GroupCollection but it doesn't seem to be
accessible.

Thanks,
Mike
 
I guess you could play around with Regex.GetGroupNames,
Regex.GetGroupNumbers, Regex.GroupNameFromNumber, etc.

Hope this help,
Thi
 
Then, what about the captured values? Can you get them as well based on
group names?

Benny
 
Back
Top