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

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
 
T

Truong Hong Thi

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

Hope this help,
Thi
 
B

Benny S. Tordrup

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

Benny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top